nuget package manager version issue VS 2013 - c#

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

Related

Upgrading Microsoft.CodeAnalysis.CSharp for Roslyn analyzer

I'm working on a Roslyn C# analyzer, and need to use the RecordDeclarationSyntax type from newer versions of the Microsoft.CodeAnalysis.CSharp nuget package from 3.3.1 to 4.2.0. Unfortunately, it seems that if I upgrade the package alone, I get the following compile error:
error NU1605: Detected package downgrade: Microsoft.CodeAnalysis.Analyzers from 3.3.3 to 2.9.8. Reference the package directly from the project to select a different version.
This makes sense, since the Microsoft.CodeAnalysis.Analyzers version should have the version corresponding with the Microsoft.CodeAnalysis.CSharp release.
If I upgrade both packages (Microsoft.CodeAnalysis.CSharp to 4.2.0 and Microsoft.CodeAnalysis.Analyzers to 3.3.3), the solution compiles, but the analyzer fails to run.
Is there any way that I can use the latest Microsoft.CodeAnalysis.CSharp APIs within an analyzer?
Be mindful when updating the version of the Roslyn packages, because it's a tooling breaking change: greater versions of Roslyn require greater versions of the .NET SDK / Visual Studio (which ships with a .NET SDK in-box) as a consumer.
Have a look at the compatibility of the Roslyn NuGet packages.
If you publish your .NET Analyzers publicly (e.g. via NuGet.org), I suggest targeting the lowest version of Roslyn necessary (where the respective major version of the .NET SDK is still supported) for the widest range of compatibility:
When you just need the C# 9.0 RecordDeclarationSyntax, then prefer targeting Microsoft.CodeAnalysis.CSharp 3.8.0, which requires the .NET SDK 5.0.100 / Visual Studio 2019 v16.8.0.
When you also require the C# 10 ClassOrStructKeyword on record, then prefer targeting Microsoft.CodeAnalysis.CSharp 4.0.1, which requires the .NET 6 SDK 6.0.100 / Visual Studio 2022 v17.0.0.
If you publish and consume your .NET Analyzers within a controlled environment (e.g. within your organization), then I guess targeting the latest version of Roslyn is fair, with the requirement of keeping the .NET SDK / Visual Studio also up to date.
In case someone else has this issue, it took a little bit of digging around, but I ended up needing to update Visual Studio to the latest version, and the .NET SDK to the latest LTS.

Is there a Visual Studio 2022 .Net 6.0 compatible version of Microsoft.Express.Drawing?

I would like to create a WPF custom control circular progressbar.
Earlier versions of .Net would support the Microsoft.Expression.Drawing nuget package download which made Arc creation really simple.
I am developing with Visual Studio 2022 and .Net 6.0 .
If I try to download the Microsoft.Expression.Drawing nuget package, an error message is produced saying that some parts of the package are not compatible.
Is there a viable substitution?
It looks like it's baked in now if you take a look at the WPF to .NET6 migration guide.
At least some of the blend namespaces are included.
NetCore5.0.Microsoft.Expression.Drawing nuget package

Roslyn: Missing method exception for VSIX package

I have problems since I have updated "Microsoft.CodeAnalysis.CSharp.Scripting" to 1.3.2.
Steps to reproduce:
Create a VS add-in with EditorMargin class.
Change .NET to 4.6
Install Microsoft.CodeAnalysis.CSharp.Scripting and Microsoft.CodeAnalysis.CSharp.
Put somewhere in ctor the following code:
var t = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)
After running the add-in it will throw a
Missing method exception
It cannot find a constructor of CSharpCompilationOptions. I noticed that when I don't install "Microsoft.CodeAnalysis.CSharp.Scripting" (which is not necessary in the above case), everything works. I guess one of dependencies of Microsoft.CodeAnalysis.CSharp.Scripting installs some packages.
I tried to run "Fuslogvw" to see if there are any binding errors but I could not find anything useful.
Any ideas?
Update
- I use Visual Studio 2015 update 3
Update 2
I downgraded "System.Collections.Immutable" from 1.2.0 to 1.1.37 and it works again.
Update 3
I found the reported bug:
https://github.com/dotnet/roslyn/issues/12247
The problem is I need to use 1.2.0 because Roslyn scripting API uses that version.
The current workaround for me is to downgrade Microsoft.CodeAnalysis.Csharp.Scripting to the version which works with "System.Collections.Immutable 1.1.37"
If you're targeting package version 1.3.2, that means you're targeting Visual Studio 2015 Update 3, but I'm guessing you don't have that installed. Either downgrade to an older version (i.e. 1.2 if you're targeting Update 2, 1.1 if targeting Update 1), or upgrade your VS to a newer version.
I was able to resolve this problem installing Visual Studio 2017. VS 2017 requires System.Collection.Immutable 1.2.1.0, which does not conflict with other Roslyn versions

How to install protobuf-net on Visual Studio 2012 using NuGet?

I would like to install protobuf-net using NutGet and Visual Studio 2012.
However, if I try to install it, I got the following error message from NuGet :
'protobuf-net' already has a dependency defined for
'NETStandard.Library'.
I have tried to install NETStandard.Library but there is an error :
The 'NETStandard.Library 1.6.0' package requires NuGet client version
'2.12' or above, but the current NuGet version is '2.8.60318.667'.
I also tried to update NuGet (by uninstalling it then re-install), but it seems with Visual Studio 2012 it is stuck to 2.8 version.
I don't have Visual Studio 2012 to test, but I wonder if this is due to the way Nuget now works with the .Net Core dependencies. It should work if you install an older version of protobuf-net. You can see that the older version doesn't mention .NETStandard as a dependency. To do this, from the package manager console, type this:
Install-Package protobuf-net -Version 2.0.0.668
I found that this protobuf-portable-net works on .NET 4.5 for VS 2013 and has the same version number as above: 2.0.0.668. It's the same author and might be a better approach than intentionally installing an old version of a newer package.

How to enable C# 6.0 feature in Visual Studio 2013?

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.

Categories