Workaround with Roslyn compiler such that visual studio 2013 "understand" - c#

As I learn that I can compile C#6.0 code to run on lower .NET framework,
Does C# 6.0 work for .NET 4.0?
Post-Answered Note: I realized that the post above only shows that C#6.0 can compile
on .NET 4.0. For lower .NET, here is the answer from Mr. Jason
Malinowski, who works on the Roslyn project:
"I can't think of a reason why it wouldn't work, but I'm not sure how
much that has been tested"
I learn how to code in C#6.0 in Visual Studio 2013 and I read some posts regarding the topic:
Using Roslyn compiler with Visual Studio 2013
How to enable C# 6.0 feature in Visual Studio 2013?
How can I add C# 6.0 to Visual Studio 2013?
And also watching a video:
https://www.youtube.com/watch?v=tTdhlJFzCRA
What I basically understand from them are:
You can have C#6.0 feature enabled in VS2013 by using Roslyn Compiler
You could use Microsoft.Net.Compilers NuGet package to use Roslyn compiler, but with the cost that the VS2013 itself won't "understand" some codes since the VS2013's internal "live" compiler is not the same as Roslyn.
There was once upon a time where such is supported. https://github.com/dotnet/roslyn but the latest version for this is April's End.
(Side question: Anything wrong with my understanding?)
Now my questions are:
As of now, is the a way to workaround with Microsoft.Net.Compilers NuGet package and VS2013 internal "live" compiler such that it can "understand" C#6.0?
"There was once upon a time where such is supported" how can I get this project. As I download the project from github and tried to open it with VS2013, I got the following error:
Can we still use the April's End version well in VS2013 that it will understand what it tries to compile?
Any other workaround for this? I would be happy as long as I can code with C#6, using VS2013, and compile it to lower .NET framework.
Thanks!
Note: Unfortunately, using Visual Studio 2015 is not an option for me...

To summarize the compatibilities and incompatibilities:
C# 6.0 (the language) can be used to compile applications that run .NET 4.0; i.e. it does not require .NET 4.5 or higher.
There is no supported way to make Visual Studio 2013 understand C# 6.0 code in the IDE. We did release, as you observe, previews of pre-6.0 things that ran on Visual Studio 2013. Those were just intended to be previews while we finished all the work of making Visual Studio 2015.
You can install the NuGet package to make the build use C# 6.0 under Visual Studio 2013, but the IDE will still not understand C# 6.0 features and Intellisense and friends will be broken.
To build the Roslyn source code as-is (and of this writing), you need Visual Studio 2015 with Update 1, or equivalent tools for Mac/Linux.

Related

Can newer versions of MSBuild compile older C# solutions?

I've inherited a set of build scripts which currently look inside the .sln file, work out what version of Visual Studio they were created with, and then call the version of MSBuild associated with that version of VS.
Is that necessary? Or will the latest version of MSBuild compile older solutions/projects?
Can newer versions of MSBuild compile older C# solutions?
The simple answer is yes.
When building the project from Visual Studio, Visual Studio will call devenv.exe to build the project, then devenv calls msbuild to perform the build.
As per official document Port, Migrate, and Upgrade Visual Studio Projects:
Each new version of Visual Studio generally supports most previous types of projects, files, and other assets. You can work with them as
you always have, and provided that you don't depend on newer features,
Visual Studio preserves backwards compatibility with previous versions
like Visual Studio 2015, Visual Studio 2013, and Visual Studio 2012.
Support for some types change over time, however. A newer version of Visual Studio may no longer support certain types, or require that
they be migrated and updated such that they're no longer
backwards-compatible.
So the latest version of MSBuild supports most previous types of older solutions/projects except those no longer support by the newer version of MSBuild.

Is it possible build a version of Roslyn in Visual Studio 2015?

With the current source code, projects which won't load in VS 2015. I also tried some older branches and while the projects load, they seem to be dependent on packages that are no longer available. I don't mind if its older version.
If you look at the tag on the github repository for version 1.0 that should build under Visual Studio 2015

Targeted .NET framework for the project depends on Visual Studio version?

I have a funny situation where the C# project targets version of .NET framework depending on Visual Studio version rather than depending on selected .NET target version in Application tab of project's properties.
I had VS2013 premium, update 4, installed and the given project targets .NET 3.5.
Afterwards I've installed VS2015 Enterprise edition and opened solution with the given project with VS2015. Resharper suggested use of nameof() operator (which is .NET 6.0 feature) and this compiled, but when I open given solution in VS2013 it doesn't compile anymore.
Here's the screenshot of Application tab for the given project:
Here's the code snippet from the project when I open it in VS2015:
Which compiles successfully.
And here's the code snippet from the project when I open it in VS20103:
Which doesn't compile.
Any clues about this?
UPDATE:
To rephrase my question. Why does the given project (that targets .NET 3.5) compile at all in VS2015 even though I've used .NET 6.0 feature (nameof() operator)?
This is normal behaviour. If you try to compile something .NET 4.0 specific in VS 2005, you will get the same result. Using a certain VS version you can only develop using up to a certain .NET version.
If I remember correctly:
VS 2005 - .NET 2.0
VS 2008 - .NET 3.5
VS 2010 - .NET 4.0
VS 2013 - .NET 4.5
Update:
The .NET version is indeed not relevant in this case, as the nameof operator is a feature of the Roslyn compiler. Nothing more, nothing less. The VS 2013 definitely uses a different one (at least a compiler which does not cover up with C# 6), therefore it does not compile.

Will Roslyn be part of the .NET framework?

Will Roslyn be part of the .NET framework?
Which version and when?
It is actually available at GitHub but it is fairly big and I'm not able to load it in Visual Studio 2013 on Windows 7 without errors.
No, Roslyn is not included in the .Net Framework. Note that, even in .Net Framework 4.6 you'll still find the legacy csc.exe and vbc.exe compilers which we ship for compatibility reasons. They don't support the latest language features and, at release, you'll see that we've changed their banner text to make it clear that these are not the latest versions.
To get the Roslyn-based C# and VB command-line compilers, you have two options:
Install Visual Studio 2015 RC. or
Install the MSBuild_tools installer package.
You'll find the Roslyn-based command-line compilers at %ProgramFiles(x86)%\MSBuild\14.0\bin
Does Roslyn will be part of the .net framework? Which version and
when?
Roslyn will be officaly shipping with Visual Studio 2015 RTM, which is currently in RC (which you can download and try). It is no longer available for VS2013. Generally, there is also a nice web hosted roslyn compiler called TryRoslyn if you want to try it out.

MSIL - Can I find the Visual Studio version that was used to build/compile a .NET assembly?

Is the program name that was used to build the assembly written into the assembly available anywhere in the MSIL code?
Visual Studio doesn't build anything - Visual Studio uses MSBuild to do its building1:
Visual Studio hosts MSBuild to load and build managed projects.
In fact you can build MSIL code without Visual Studio by downloading Microsoft Build Tools:
If you don't have Visual Studio installed on your computer, you can use Build Tools 2013 to build managed applications. The Visual Basic and C# compilers are also included in this download. (In earlier versions, these tools were included in the stand-alone .NET Framework.)
Any compiler which satisfies the ECMA 335 standard can compile valid Common Language Infrastructure (CLI) applications - the Mono C# compiler is one such example.
In other words, I don't think it's possible to obtain information about the Visual Studio version from the assembly.
Unless some additional metadata is added to the assembly by Visual Studio (I don't think it is), to find out what version of Visual Studio built a specific assembly, you'd have to do something like adding your own custom attributes to the assembly, which you could then use reflection to retrieve.
Obviously, you can rule out earlier versions of Visual Studio based on the .NET version that the assembly targets (e.g. Visual Studio 2012 was the first to support .NET 4.5).
This table is compiled from the Wikipedia article for Visual Studio:
.NET Min Visual
Studio version
1.0 2002 (7.0)
1.1 2003 (7.1)
2.0 2005 (8.0)
3.0 2005 (8.0)
3.5 2008 (9.0)
4.0 2010 (10.0)
4.5 2012 (11.0)
4.5.1 2012 (11.0)
4.5.2 2012 (11.0)
4.6 2015 (14.0)
1 Visual Studio 2015 and above, by default, uses the new Roslyn compiler to compile.

Categories

Resources