How to set up VS 2013 to work with Tuples [duplicate] - c#

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.

Related

How does implicit FSharp.Core reference work in an fsproj?

Months ago I had build a Windows app using a mix of C# and F# projects. The C# project uses FSharp.Core 5.0.0. I had not noticed this until today, but the .fsproj does not specify a version of FSharp.Core. This hasn't been an issue and successfully builds on my local machine using Visual Studio 2019 (all projects are using 5.0.0).
Today, a colleague of mine cloned the repo and tried building the project, only to get a build error for a detected package downgrade of FSharp.Core from 6.0.5 to 5.0.0. My colleague uses Visual Studio 2022 and noticed while the C# project was using FSharp.Core 5.0.0 (as explicitly specified in the .csproj), the F# projects were using 6.0.5.
I've done a bit of reading with what I could find for FSharp.Core implicit references, but don't really understand how the version is selected or how to remedy this situation.
How does Visual Studio figure out which version of FSharp.Core it wants to use for FSharp projects and how can I insure uniform behavior on different machines and versions of Visual Studio.
FSharp.Core is defined in the F# targets loaded by build tooling. It's pinned to the latest released version for the .NET SDK you're using.
You can ready here about using it with C# projects: https://github.com/dotnet/fsharp/blob/main/docs/fsharp-core-notes.md#c-projects-referencing-f-projects-may-need-to-pin-fsharpcore

System.Net.Http from visual studio's assemblies vs nuget package

I am considering which is the difference between tis two packages. If i will search in references of visual studio i will find System.Net.Http.dll version 4.0.
But if i will look into nuget packages i will find a version 4.3.4.
Both of them are work very nice. But which of two is better to use visual studio or from nuget?
Thank you
The version you are seeing in Visual Studio is predicated on the version you are running of .Net. Each version of .Net Core's SDK could potentially have a different version of System.Net.Http.dll. What you are seeing in Nuget is the latest version, which does not appear to match the version for your currently used .Net SDK.

Using C# 7.1 with MSBuild

To use the new C# 7.1 language features with Visual Studio 2017, you add the setting <LangVersion>latest</LangVersion> to your project file(s).
However, building such projects from MSBuild (version 15.3.409.57025, located at C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin) results in an error:
CSC : error CS1617: Invalid option 'latest' for /langversion;
must be ISO-1, ISO-2, Default or an integer in range 1 to 6.
Is this feature just not yet supported by MSBuild, or is it possible to get this working?
This covers 200+ projects that were originally created variously in Visual Studio 2013 and 2015. They were all re-targeted to .NET 4.7 using the Target Framework Migrator tool (which saved lots of clicking and appears - based on inspecting .csproj file changes - to do the job correctly).
The projects all build successfully from Visual Studio 2017.
Nuget packages
Microsoft.Net.Compilers nuget package does not work and needn't to be installed.
Set the following project/build settings
Set at least C# 7.1 or higher in the Debug and Release build properties. (via: Project menu > [ProjectName] Properties > Build tab > [Advanced] button > Language Version).
Setting it to latest does not work.
Also make sure that you are running the latest MSBuild version.
Add a reference to the Microsoft.Net.Compilers package (version 2.3.x, to get C# 7.1).
A short description of the package:
Microsoft.Net.Compilers
This package not only includes the C# and
Visual Basic compilers, it also modifies MSBuild targets so that the
included compiler versions are used rather than any system-installed
versions. Once installed, this package requires Microsoft Build Tools
2015.
Make sure you have changed for "All Configuration" and not just "Debug"
else you will be baffling why it is failing at production.
In case you land here because you get the error as the OP mentioned, running msbuild via command line (e.g. from a build agent such as jenkins), the solution may be as easy as to upgrade Microsoft Build Tools 2015.
You can do that via choco install microsoft-build-tools or manually via the official Microsoft Build Tools 2015 or by updating your Visual Studio 2017 installation.
I've got a solution with a C# console app using C# 7.1 here.
Using the VS 2017 command line (and thus MSBuild 15.3.409.57025) it worked fine. (The .csproj does contain <LangVersion>latest</LangVersion>.)
Is this feature just not yet supported by MSBuild, or is it possible to get this working?
Yes it is.
Which instance of csc.exe is being run and what's its version? Because it looks like, despite quoting the version, you have the wrong version of csc.exe (the error message says 1-6 so not even C# 7 would work).
We discovered that our MVC projects were triggering this issue.
To fix, we updated the Microsoft.CodeDom.Providers.DotNetCompilerPlatform NuGet package used by these projects from version 1.0.0 to 1.0.7.

Nuget client 3.0 support

I am writing xamarin app which will work on windows and OS X (using profile 7)
I am trying to add the nuget system.xml.xpath
However, it gives me the below error-
Adding System.Xml.XPath...
The 'System.Xml.XPath 4.0.0' package requires NuGet client version '3.0' or above, but the current NuGet version is '2.8.7.0'.
I have two question-
1.
how soon will xamarin start supporting nugget client 3.0 or above?
2.
how can i resolve my specific problem?
On OS-X you can:
sudo nuget update -self
Note: sudo is required as this will update the nuget.exe within the Mono Framework
>nuget
NuGet Version: 3.4.4.1321
There is a nuget3 branch of Xamarin Studio 6.1 but I have not seen when that will go into an public alpha release...
You do not say what development environment you are using. The error message suggest you are using Xamarin Studio, since Visual Studio already supports NuGet 3.
There is a preview branch of Xamarin Studio 6.1 which does support NuGet 3, this is currently available on the alpha channel in Xamarin Studio.
However whilst using Xamarin Studio 6.1 will allow you to do is add the System.Xml.XPath NuGet package to your project you will still not be able to use anything from that NuGet package currently since there are no assemblies in it for the Xamarin frameworks and currently the Xamarin build tools will not add the correct assembly references for you at compile time.

SQLite Windows 10 RTM universal app

With the Windows 10 RTM and Visual Studio 2015 RTM SQLite doesn't work any more.
For instance, the tutorial at http://igrali.com/2015/05/01/using-sqlite-in-windows-10-universal-apps/ will not add the SQLLite.cs and SQLiteAsync.cs files to my project, also the "Microsoft Visual C++ Applocal runtime Package for Windows UAP" reference is not available for me.
The funny thing is it worked with the RC versions ...
SQLite Version:
sqlite-uap-3081101.vsix (5.73 MiB)
Using sqlite-uap-3081101.vsix with VS2015 RTM & the 10240 release of the Windows 10 SDK generates the following warnings:
The SDK "SQLite.UAP.2015, Version=3.8.11.1" depends on the following
SDK(s) "Microsoft.VCLibs.AppLocal, version=14.0", which have not been
added to the project or were not found.
This is because the SQLite extension is dependent on the AppLocal Runtime Package. In theory the package would be automatically referenced when adding the extension as a reference, however, the package no longer seems to be included in the referenced release of the W10 SDK.
The AppLocal Runtime Package has been replaced with a CRT package like W8 & W8.1 in the release versions of VS2015 + W10 SDK.
If you add a reference to "Visual C++ 2015 Runtime for Universal Windows Platform Apps" your app will build and run although there'll be warnings until the SQLite extension is updated.
Whilst you can just include SQLLite.cs and SQLiteAsync.cs from SQLite-net directly if you're using nuget to reference a library as per the tutorial then you wont see the files in your project although the classes will be available for you to use.
I think the SQLite team has already fixed the problem.
SQLite for Universal App Platform - See Q and A.
SQLite Timeline
So, just uninstall the existing SDK of SQLite from Visual Studio and install that again. After that I can't see the warning about AppLocal.

Categories

Resources