C# source code compilation from command line (any cases, without Visual Studio) - c#

Dear Community. I have faced on the case when is needed to compile C# source code without Visual Studio usage in order to build it in DLL library and then include this package into other platforms (not only Windows-based). After a little bit of investigation CMake as a build tool has been chosen and appropriate configuration file (CMakeLists.txt) created. During it's running using native command prompt there is a mistake of compilation - "C# is currently only supported for Microsoft Visual Studio 2010 and later". That's why I would like to ask you share your knowledge and provide any additional cases to build it (some additional tools or whole scenarios) such as I'm a brand new in this topic and can't proceed before that wall (; . Thank you in advance.

Related

Visual Studio 17.4.4 debug output: double-clicking solution-relative path

There are many questions that seem to be related, but they are all old, while I am almost sure this started happening with the latest update to visual studio version 17.4.4.
The problem:
In an as-concise-as-possible summary:
Double-clicking a line starting with solution-relative path in the debug output of Visual Studio in a multi-project solution opens up the file in the editor as an unusable plain text file.
As you know, if a debug output line starts with D:\Full\Path\To\SourceFile.cs(99): then it is double-clickable, and it opens the given file in the editor, and places the caret at the given line. That's immensely useful, so all my logs are in exactly that format. It can also be prefixed with optional whitespace, so all of my (indented) exception stack traces are also in that format.
The pathnames given by [CallerFileName] or StackFrame.GetFileName() are absolute, so they start from the drive letter and include the kitchen sink; in order to save screen real-estate and to produce logs that are also meaningful on machines other than the machine where the software was compiled, I have been converting all these absolute pathnames to solution-relative, and Visual Studio has been understanding them just fine. Until a couple of days ago.
So I recently upgraded my Visual Studio to version 17.4.4 and I installed/removed a whole bunch of frameworks for various things. Now, I am having the following problem: relative path-names in the output window still work for single-project solutions where the project is in the same directory as the solution; for multi-project solutions, the following bad thing happens:
When I double-click on a line in the debug output, Visual Studio opens the corresponding file in a new tab even if it already had it in an existing tab, and in this new tab the file is unusable: there is no syntax highlighting, no tooltips, no navigation, nothing.
The question(s):
Is anyone else experiencing this?
Has anyone found a workaround?
The Bug Report
I would have filed this bug report with Microsoft, but in order to do that they require me to authenticate first, and their authentication mechanism does not work. (I suppose that's one way of reducing the number of bug reports; J. D. Salinger would be proud.) So, here is the bug report that I would have filed.
I am programming in C# using Visual Studio with ReSharper.
I have tried the following both with DotNet Framework 4.6.2 and with DotNet 7.0.
Full version information follows at the end.
Steps to reproduce:
Create a console application, ConsoleApp2.
Uncheck the "Place solution and project in the same directory" checkbox.
At the end of the auto-generated Program.cs add the following line of code: System.Diagnostics.Debug.WriteLine( "ConsoleApp2\\Program.cs(4): Hello, Output Window!" );
Compile the solution
Close the solution and re-open it.
Launch ConsoleApp2 (with debugging)
In the debug output of Visual Studio, double-click on the line that says "Hello, Output Window!".
Expected behavior:
Visual Studio switches to the already existing tab with Program.cs, and places the caret at line 4.
Syntax highlighting continues to work as expected.
Gutter symbols continue to appear.
Code tooltips are still available.
Navigation such as go-to-definition still works.
The tooltip of a tab shows the full path of the source file.
The "Open Containing Folder" command on the tab opens the folder containing the file.
Actual behavior:
Visual Studio opens an entirely new tab, loads Program.cs in it, and places the caret at line 4.
Syntax highlighting is completely gone.
Gutter symbols have disappeared.
Code tooltips are not shown anywhere in the code.
Navigation such as go-to-definition does not work anymore.
The tooltip of a tab shows only a relative path.
The "Open Containing Folder" command on the tab gives an error message box saying "Unable to open the folder. It might have been deleted or [...]"
Notes:
If the solution and the project are in the same directory, the problem does not occur.
The problem does not occur on the first try; the step which says "Close the solution and re-open it" appears to be necessary.
If you edit text in the "phantom" tab and save it, the changes do appear in the real tab.
Why is this a big problem:
The ability to double-click on a line in the debug output window and to be taken to the source code that emitted that line is a major convenience.
When the IDE shows a wrong or otherwise unusable file, there is no way to open the right file other than carefully selecting part of the log line and pasting into the search box so as to perform a manual search for that file, which means that this major convenience is completely annulled.
Version information
From "About Microsoft Visual Studio":
Microsoft Visual Studio Community 2022
Version 17.4.4
VisualStudio.17.Release/17.4.4+33213.308
Microsoft .NET Framework
Version 4.8.04084
Installed Version: Community
ASP.NET and Web Tools 17.4.326.54890
ASP.NET and Web Tools
Azure App Service Tools v3.0.0 17.4.326.54890
Azure App Service Tools v3.0.0
C# Tools 4.4.0-6.22608.27+af1e46ad38d900023f8b1a2839484e471ece1502
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Clear MEF Component Cache 1.4
Clears the Visual Studio MEF component cache to fix issues with cache corruption.
Dotfuscator Community Edition 6.5.0+76d4669002
PreEmptive Protection - Dotfuscator CE
Extensibility Essentials 2022 1.1.14
A collection of extensions that makes it much easier to write Visual Studio extensions
Extensibility Margin 1.0.9
Shows relevant information about the current file and language to extensibility authors
Extensibility Message Bus 1.4.1 (main#2ee106a)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.
Image Manifest Tools 1.1.8
Makes it easier to create and maintain .imagemanifest files for Visual Studio extension
Insert Guid 1.3.6
Makes it super easy to insert a new GUID into any editor and input field
KnownMonikers Explorer 2022 1.2.42
A tool window for Visual Studio extension authors to explore the KnownMonikers image collection
Markdown Editor v2 2.0.132
A full featured Markdown editor with live preview and syntax highlighting. Supports GitHub flavored Markdown.
Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines
Mono Debugging for Visual Studio 17.4.19 (8c0a575)
Support for debugging Mono processes with Visual Studio.
NuGet Package Manager 6.4.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/
Pkgdef Language 1.3.88
Full language support with IntelliSense, validation, outlining, and more for .pkgdef and .pkgundef files
Razor (ASP.NET Core) 17.0.0.2246202+61cc048d36a3fc9246d2f04625988b19a18ab8f0
Provides languages services for ASP.NET Core Razor.
TypeScript Tools 17.0.10921.2001
TypeScript Tools for Microsoft Visual Studio
Visual Basic Tools 4.4.0-6.22608.27+af1e46ad38d900023f8b1a2839484e471ece1502
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Visual F# Tools 17.4.0-beta.22512.4+525d5109e389341bb90b144c24e2ad1ceec91e7b
Microsoft Visual F# Tools
VisualStudio.DeviceLog 1.0
Information about my package
VisualStudio.Mac 1.0
Mac Extension for Visual Studio
VS Theme Colors 2022 1.0.11
Makes it easy to browse all the brushes and select the right theme color for your Visual Studio extension UI.
VSCode Theme Converter 1.0.15
A super easy way to convert VS Code themes to Visual Studio using the official CLI tool under the hood
VSColorOutput64 2022.2
Color output for build and debug windows - https://mike-ward.net/vscoloroutput
VSIX Synchronizer 1.0.27
Provides the ability to generate code-behind files for .vsixmanfiest and .vsct files in managed code to make the information easy to consume from the rest of the extension.
VSPackage Extension 1.0
VSPackage Visual Studio Extension Detailed Info
Xamarin 17.4.0.312 (d17-4#be7e8d1)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.
Xamarin Designer 17.4.0.138 (remotes/origin/d17-4#d36bba3cc9)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.
Xamarin.Android SDK 13.1.0.1 (d17-4/13ba222)
Xamarin.Android Reference Assemblies and MSBuild support.
Mono: a96bde9
Java.Interop: xamarin/java.interop/d17-4#fcc33ce2
SQLite: xamarin/sqlite/3.39.3#23e1ae7
Xamarin.Android Tools: xamarin/xamarin-android-tools/main#0be567a

Can't Find Source Code of Live Share for Visual Studio (Windows, and not The VS Code Version)

When I try to I Only find the linux version for VS Code.
The problem is the fact that it's built in to vs and therfore I can't find its source code.
Live Share is not currently an open source product!
As of this date (2021-02-14): The code is not available under any license. You can’t review, contribute or even compile the code because it is totally unavailable.

Now that VS2015 is out, what's a supported way to modify Roslyn, with debugging support?

The Context
We'd like to modify Roslyn and be able to debug it while compiling with it. Pre-VS2015 release, doing this was a painful process that didn't flow very well.
Our goal is to develop a C# variant compiler.
The Dream
Pre-VS2015, executing and debugging your modded Roslyn required the opening of a second VS IDE (experimental) set to use your modded Roslyn. This process wasn't straight forward to setup properly, and oftentimes would break your VS2015 installation.
Post-VS2015, is there a better setup and process possible to modify and debug Roslyn?
I have installed Visual Studio 2015 but it looks like I need more required bits. After that I'm unsure how to run the tests and try the changes in VS2015.
We have our current documented process of testing your own versions of Roslyn here. As long as you're on Visual Studio 2015 Update 1 or later (where we did all the work to support this), everything should work.
The executive summary of those instructions is if you now enlist into Roslyn, you can choose the "VisualStudioSetup" project and just hit F5 to run. That builds to .vsix files in your build directory you can also install. If you want to, there's a CompilerExtension project that produces a compiler you can build with.

Know Which compiler is used in visual studio 2015? [duplicate]

I've a bit of confusion about roslyn.
What I have done:
I've installed vs 2015 community edition and download in extensibilty > download compiler platform sdk.
So I created a simple console application: hello world example.
Well now I'm expect to choise the c# compiler between the vs2015 default one and roslyn..., but I've not found such option.
So my first question is: how to select version of c# compiler?
Second I've downloaded master-roslyn and I build, then I found csc.exe, well the odd things is that if I lauch the exe
I get c# compiler version 42.42.42.42. ???? Right?
Then I've follow some tutorials, but all purpose me:
to load a source from text file or string vars and analyze or change syntax tree, then compile to var.
Well at this point I'm confused... So:
What is roslyn exactly? A meta compiler? This mean that I can change my code at runtime just like Reflection?
Second: how can compile with vs2015 with default csc or choose roslyn?
third: If I build a custom version of roslyn How can I compile my source using Vs2015 ?
Which know if csc.exe is roslyn? No help or command line print the codename.
Thanks
So it looks like you've got a few questions:
What is Roslyn?
Roslyn is the new default compiler inside of Visual Studio 2015. If you're building and running applications within Visual Studio 2015, they're being compiled with the Roslyn compiler. You'll get to take advantage of all the new C# 6 features that are available only within the new compiler.
If you're using VS2015, Roslyn has replaced the old compiler entirely and as far as I know you can't use the old compiler within VS 2015.
Roslyn is also a platform that allows you to build programs that can modify, interpret and understand other programs. It's not really meant to let you write code that modifies itself (although that's probably possible to a degree).
The common use cases for Roslyn are:
Building Code Analyzers that provide errors and warnings within Visual Studio.
Building extensions for Visual Studio that understand source code.
Building other tools that understand or run source code. Example: ScriptCS - Scripting with C# code.
In order to use Roslyn for these purposes, you pull down the Microsoft.CodeAnalysis packages from NuGet. You can use these packages to parse code, analyze syntax trees, analyze symbols or compile code and emit IL.
If you're interested in learning more about Roslyn, I've started a series called Learn Roslyn Now that you might be interested in.
Can I replace the compiler?
Yes you can, but I'm not convinced this is a great idea outside of testing changes you want to contribute back to Roslyn. You can pull down Roslyn from GitHub and follow these instructions to build and run Roslyn from within Visual Studio.
If you follow those instructions, you'll be able to run the Roslyn project with F5. It will start a new instance of Visual Studio that's using your customized compiler. This is how people outside of Microsoft will contribute features to the compiler from now on. (Previously you couldn't deploy your custom compiler to Visual Studio but they fixed that in Visual Studio Update 1).
Roslyn is two things:
An API that lets you see "compiler things" like syntax trees and symbols.
A new csc.exe that is implemented atop #1.
If you want to make changes to the compiler and use that to build, take a look at these instructions if you haven't already. There's a few different ways you can make your own version of csc.exe and then use that to build something. But there's no "choice" dialog like you're looking for.
Roslyn is the default compiler of Visual Studio 2015. So, if you install VS2015 you´re already using Roslyn.
Roslyn is a codename for .NET Compiler Platform, and it provides open-source C# and Visual Basic compilers. The project is available on github.

Code Contracts support in Visual Studio Express 2013

I've been developing a C# project in Visual Studio Express 2013 and came across Code Contracts for .NET languages. Impressed by their brevity and the static analysis tool that came with them, I started using them in my code base. However, when I attempted to run my program, I was met by an error message similar to the one found in this SO thread, i.e.
...An assembly (probably "<my project>") must be
rewritten using the code contracts binary rewriter (CCRewrite) because
it is calling Contract.Requires and the CONTRACTS_FULL symbol is
defined. Remove any explicit definitions of the CONTRACTS_FULL symbol
from your project and rebuild...
Guides suggest that to fix this, I have to enable Code Contracts from my project's Properties page, but a Code Contracts Properties entry is nowhere to be found in Express.
Some MSDN forum threads seem to indicate that all the tooling for Code Contracts is included in the Express version, but the Code Contracts Properties page is not. This seems to be the case, as I was able to run my project in VSE 2013 only after enabling Code Contracts with a copy of Visual Studio 2012 Ultimate I acquired from my university before graduating.
Is there really no way to work with Code Contracts in Visual Studio Express except by modifying the project files either manually or with a paid version of Visual Studio? If this is the case, I am extremely hesitant to use them at all, since my company is unlikely to purchase VS licenses. Futhermore, it seems extremely odd that Microsoft would attempt to proliferate this new and superior verification paradigm but then restrict it to paying customers only.
You can probably use the new VS Community 2013, as long as you meet the licensing requirements:
http://www.visualstudio.com/en-us/visual-studio-community-vs
Here’s how Visual Studio Community can be used in organizations:
An
unlimited number of users within an organization can use Visual Studio
Community for the following scenarios: in a classroom learning
environment, for academic research, or for contributing to open source
projects.
For all other usage scenarios: In non-enterprise
organizations, up to 5 users can use Visual Studio Community. In
enterprise organizations (meaning those with >250 PCs or > $1 Million
US Dollars in annual revenue), no use is permitted beyond the open
source, academic research, and classroom learning environment
scenarios described above.
It's basically VS 2013 Professional for free so you can install the code contracts extension.
The problem is your edition of Visual Studio. You are running Visual Studio 2013 Express edition, as you stated. In order to use the binary re-writer from within Visual Studio, you need to install the Code Contracts extensions. These you can download from Microsoft's Research in Software Engineering (RiSE) site, which is packaged as a Windows Installer.
The installer installs the binary re-writer that is required, as well as a bunch of Visual Studio extensions. Unfortunately, Code Contracts states in their manual on page 40 that they don't support the various Visual Studio Express editions. You'll need to at least have Visual Studio 2013 Professional edition in order to use the Code Contracts binary re-writer extension from within Visual Studio, and in order to see the Code Contracts tab on the project properties window.
Code Contracts performs assembly re-writing as a post-build step. Meaning, Visual Studio first compiles the .NET code as it normally would. But, when using Code Contracts and enabling the right options on your project (assuming the VS extensions are installed—which you can't do in Express editions), then the binary re-writer is called for you by Visual Studio after the normal compilation process.
Instead, after compiling your program, you'll need to manually run the ccrewrite program installed by Code Contracts on the compiled assembly (and all dependent assemblies) to 're-write' your assemblies, which will add in all the Code Contract checking information. See the Code Contracts documentation (also available on the RiSE website) for information on how to do this.
Contracts are supposed to be useless for Visual Studio Express 2013 (at least Code Contracts come with a plugin for all non-express versions).
So one has to define the symbol CONTRACTS_FULL in project properties -> build -> general -> conditional compilation symbols.
And then add the proper call to ccrewrite.exe to the post-build event command line found under project properties -> build events. The command should be set to something like
"C:\Program Files (x86)\Microsoft\Contracts\Bin\ccrewrite.exe" -throwOnFailure "$(TargetPath)"
I successfully used this tonight with NUnit. Using contracts, my unit tests don't need to check for post conditions explicitly.

Categories