Is Roslyn the default compiler in Visual Studio 2017?
I found this article
which tells that Roslyn is not the default compiler and you should install Nuget packages to enable Roslyn.
Nuget packages:
Microsoft.CodeDom.Providers.DotNetCompilerPlatform
Microsoft.Net.Compilers
But I also saw an answer on stackoverflow that says, Roslyn is the default compiler starting from VS 2015.
And when i am install that nuget packages, it's creating a new folder in /bin
with name 'roslyn'
Yes, Roslyn is the default compiler in Visual Studio.
In the article you link, it only says you need to install it separately if you are trying to use it without Visual Studio:
To date, Roslyn has remained a part of Visual Studio 2015 and is installed together with it. Roslyn is a part of Visual Studio 2017 as well. It has been released in March 2017.
However, Roslyn is not included in the .NET Framework. Even in the .NET Framework 4.6 version, the traditional csc.exe and vbc.exe compilers are included. This is done for it to be compatible with previous .NET Framework versions.
To install Roslyn compilers without installing Visual Studio, you need to download and install Microsoft Build Tools. Roslyn can also be downloaded from Github, then you can compile and get binary files csc.exe and vbc.exe, which can be accessed from the command line.
You would typically only need those NuGet packages if you were building an application or service for compiling code (or similar), which is what that article is about. That is, when your application is actually using Roslyn at runtime to process code, rather than itself being built with Roslyn.
Related
I have same problem like someone have here:
Visual Studio get stuck on "Restoring packages for solution"
I try the following:
Clear nuget cache from Tools menu. and temp, %temp% folders from RUN command.
Clear visual studio cache from here. C:\Users\Dell\AppData\Roaming\Microsoft\VisualStudio\17.0_27e1b93f
Clear .vs hidden folder of solution.
Clean and Rebuild Solution. But stuck into Restoring Nuget packages...)
I wait 15 minutes. But nothing happened.... (There's bug here?)
I only use less than 7 nuget packages from nuget.org
Here's Visual Studio Log:
Microsoft Visual Studio Community 2022
Version 17.2.6
VisualStudio.17.Release/17.2.6+32630.192
Microsoft .NET Framework
Version 4.8.03761
Installed Version: Community
.NET Core Debugging with WSL 1.0
.NET Core Debugging with WSL
ASP.NET and Web Tools 2019 17.2.393.26812
ASP.NET and Web Tools 2019
Azure App Service Tools v3.0.0 17.2.393.26812
Azure App Service Tools v3.0.0
Azure Functions and Web Jobs Tools 17.2.393.26812
Azure Functions and Web Jobs Tools
BusinessObjectEditor 1.0
Information about my package
C# Tools 4.2.0-4.22281.5+8d3180e5f00d42f0f0295165f756f368f0cbfa44
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.
CreateLayoutWizard 1.0
Create layout wizard.
Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines
NuGet Package Manager 6.2.1
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/
Razor (ASP.NET Core) 17.0.0.2218101+885a343b00bcab620a90c1550c37dafd730ce984
Provides languages services for ASP.NET Core Razor.
SQL Server Data Tools 17.0.62204.01010
Microsoft SQL Server Data Tools
TypeScript Tools 17.0.10418.2001
TypeScript Tools for Microsoft Visual Studio
Visual Basic Tools 4.2.0-4.22281.5+8d3180e5f00d42f0f0295165f756f368f0cbfa44
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.1.0-beta.22329.1+702b8e77f5fbfe21e6743324c1750503e02f182d
Microsoft Visual F# Tools
Visual Studio IntelliCode 2.2
AI-assisted development for Visual Studio.
More Information:
I use old *.csproj project template (non-sdk)
I use PackageReference not packages.config
.NET 4.8
Windows 7
No proxy used. and official nuget.org/api/.... works in browser.
NOTE: this happened when I re-installed operating system.... Sometimes it took time. Sometimes it freeze and hangs on Restoring Nuget packages... message
Please how to solve that?
According to your description I think the problem is that you used PackageReference and use nuget.exe to restore the packages.
We can see from this link that For projects migrated to PackageReference, use msbuild -t:restore to restore packages instead.
You can try msbuild -t:restore instead of nuget restore ***.csproj to restore packages if you are using PackageReference. For more details, please refer to the above link
While it is correct to consider the msbuild alternative when using command line, it is still very annoying for anything inside Visual Studio 2022. I am hitting it on many scenarios, like trying to run tests after build was successful.
Fortunately, it is now fixed in the latest Visual Studio 17.5.0 Preview 6.0
https://visualstudio.microsoft.com/vs/preview/
I want to switch target for Portable Class Library project from classic profiles to .Net Standard. The problem is that it creates project.json file which is deprecated. If I install any nuget packages, it also leads to updating this file rather than .csproj. I use Visual Studio 2015 and latest version of .NET Core tools for Visual Studio 2015 (Preview2.0.3). Does it mean that I have to switch to VS 2017 or is there a proper way to deal with updated .csproj format and .Net Standard using VS 2015?
If you want to use csproj, you need to use VS 2017.
Even though csproj for VS 2015 is usable, it involves a lot of hacks and isn't really documented or officially supported (and afaik break in VS 2017 without a migration path), so I strongly suggest to stick with project.json or migrate to VS 2017.
Visual Studio 2017 (15.x) supports C# 7, but what about Visual Studio 2015 (14.x)?
How can I use C# 7 with it?
You can replace the compiler shipped with Visual Studio for a C# 7-enabled version by installing the Nuget package Microsoft.Net.Compilers:
Referencing this package will cause the project to be built using the
specific version of the C# and Visual Basic compilers contained in the
package, as opposed to any system installed version.
There is no indication that I can see on the package page as to whether this is officially supported in Visual Studio 2015. My not-thorough tests so far indicate that it works but not painlessly - C# 7 code compiles, but is underlined with the red squiggly line which indicates a syntax error:
Note that you will also need to install the Nuget package System.ValueTuple to use the new C# 7 value tuples features.
In my case, installing just Microsoft.Net.Compilers didn't work. Instead, I had to do the following:
Install Microsoft.CodeDom.Providers.DotNetCompilerPlatform for the project (Tools => NuGet Package Manager => Manage Nuget Packages for Solution...) and install Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Install the latest Microsoft.Net.Compilers for the project
Install any other NuGet package for the latest C# feature you want to use. In my case, my goal was to use Tuples, so I installed System.ValueTuple and worked fine.
But still note that C# codes which are not known by Visual Studio 2015 default compiler will still have red squiggles underneath.
I am using VS 2013 and .Net 4.5/4.6. I am not getting this error message:
The 'System.Collections 4.0.10' package requires NuGet client version '3.0' or above, but the current NuGet version is '2.8.60723.765'.
My understanding is that this is due to a ddl that use a higher version of .Net. Just curious is there a way to fix this (e.g. determine the responsibel dll[s])?
Those packages are primarily designed for .NET Core ecosystem,
https://www.nuget.org/packages/System.Collections/4.0.10
That means it should not be used for .NET 4.5 and Visual Studio 2013. I guess that's probably why Microsoft only releases NuGet 3.* for Visual Studio 2015. It makes sense to avoid polluting Visual Studio 2013 users with the brand new bits.
A workaround is to specify a version of a NuGet your client is actually compatible with.
i.e.
System.Collections Version=x.x.x picking of course a slightly older version than the latest one.
You need to update your nuget package manager.
You can download the latest version over here:
https://visualstudiogallery.msdn.microsoft.com/4ec1526c-4a8c-4a84-b702-b21a8f5293ca
I was going through the latest features introduced in C# 6.0 and just followed an example of auto property initializer,
class NewSample
{
public Guid Id { get; } = Guid.NewGuid();
}
but my IDE did not recognize the syntax.
I am wondering how I could enable C# 6.0 in Visual Studio 2013. The Target framework I am using is 4.5.1.
Under VS2013 you can install the new compilers into the project as a nuget package. That way you don't need VS2015 or an updated build server.
https://www.nuget.org/packages/Microsoft.Net.Compilers/
Install-Package Microsoft.Net.Compilers
The package allows you to use/build C# 6.0 code/syntax. Because VS2013 doesn't natively recognize the new C# 6.0 syntax, it will show errors in the code editor window although it will build fine.
Using Resharper, you'll get squiggly lines on C# 6 features, but the bulb gives you the option to 'Enable C# 6.0 support for this project' (setting saved to .DotSettings).
As mentioned by #stimpy77: for support in MVC Razor views you'll need an extra package (for those that don't read the comments)
Install-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform
If you want full C# 6.0 support, you'll need to install VS2015.
Information for obsoleted prerelease software:
According to this it's just a install and go for Visual Studio 2013:
In fact, installing the C# 6.0 compiler from this release involves little more than installing a Visual Studio 2013 extension, which in turn updates the MSBuild target files.
So just get the files from https://github.com/dotnet/roslyn and you are ready to go.
You do have to know it is an outdated version of the specs implemented there, since they no longer update the package for Visual Studio 2013:
You can also try April's End User Preview, which installs on top of Visual Studio 2013.
(note: this VS 2013 preview is quite out of date, and is no longer updated)
So if you do want to use the latest version, you have to download the Visual Studio 2015.
A lot of the answers here were written prior to Roslyn (the open-source .NET C# and VB compilers) moving to .NET 4.6. So they won't help you if your project targets, say, 4.5.2 as mine did (inherited and can't be changed).
But you can grab a previous version of Roslyn from https://www.nuget.org/packages/Microsoft.Net.Compilers and install that instead of the latest version. I used 1.3.2. (I tried 2.0.1 - which appears to be the last version that runs on .NET 4.5 - but I couldn't get it to compile*.) Run this from the Package Manager console in VS 2013:
PM> Install-Package Microsoft.Net.Compilers -Version 1.3.2
Then restart Visual Studio. I had a couple of problems initially; you need to set the C# version back to default (C#6.0 doesn't appear in the version list but seems to have been made the default), then clean, save, restart VS and recompile.
Interestingly, I didn't have any IntelliSense errors due to the C#6.0 features used in the code (which were the reason for wanting C#6.0 in the first place).
* version 2.0.1 threw error The "Microsoft.CodeAnalysis.BuildTasks.Csc task could not be loaded from the assembly Microsoft.Build.Tasks.CodeAnalysis.dll. Could not load file or assembly 'Microsoft.Build.Utilities.Core, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
UPDATE One thing I've noticed since posting this answer is that if you change any code during debug ("Edit and Continue"), you'll like find that your C#6.0 code will suddenly show as errors in what seems to revert to a pre-C#6.0 environment. This requires a restart of your debug session. VERY annoying especially for web applications.
It worth mentioning that the build time will be increased for VS 2015 users after:
Install-Package Microsoft.Net.Compilers
Those who are using VS 2015 and have to keep this package in their projects can fix increased build time.
Edit file packages\Microsoft.Net.Compilers.1.2.2\build\Microsoft.Net.Compilers.props and clean it up. The file should look like:
<Project DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>
Doing so forces a project to be built as it was before adding Microsoft.Net.Compilers package
It is possible to use full C# 6.0 features in Visual Studio 2013 if you have Resharper.
You have to enable Resharper Build and voilá!
In Resharper Options -> Build - enable Resharper Build and in "Use MSBuild.exe version" choose "Latest Installed"
This way Resharper is going to build your C# 6.0 Projects and will also not underline C# 6.0 code as invalid.
I am also using this although I have Visual Studio 2015 because:
Unit Tests in Resharper don't work for me with Visual Studio 2015 for some reason
VS 2015 uses a lot more memory than VS 2013.
I am putting this here, as I was looking for a solution for this problem for some time now and maybe it will help someone else.
It seems there's some misunderstanding. So, instead of trying to patch VS2013 here's and answer from a Microsoft guy: https://social.msdn.microsoft.com/Forums/vstudio/en-US/49ba9a67-d26a-4b21-80ef-caeb081b878e/will-c-60-ever-be-supported-by-vs-2013?forum=roslyn
So, please, read it and install VS2015.