I have a project running .NET Framework 4.8 and in the project's properties under "Build > Advanced > Language Version" Visual Studio states "Automatically selected based on framework version". Wouldn't it be great, if they were to show me which version was automatically selected? :o/
According to https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version (amongst others) my project should be using C# 7.3, but I cannot use the latest features. "Latest" as in "as far as Microsoft will let me go with the old .net Framework".
How can I determine which C# version is being used and how can I update to the "latest" version?
I have no idea if it is possible to view the currently selected lang version from within visual studio. But it is fairly easy to specify the latest version.
From the same article you linked, edit your csproj file in a text editor and add the line <LangVersion>latest</LangVersion>, For example:
<PropertyGroup>
<LangVersion>latest</LangVersion>
</PropertyGroup>
You should also be able to specify preview as the langversion to get the preview version.
Note that not all language versions are supported for all .net platforms, so using this on .Net framework might not technically be supported. But I have been running the latest version on .net 4.8 and not noticed any major issues so far. The most noticeable issue is having to manually edit all the csproj files.
Related
I tried installing .net framework 4.7.2, still the target framework is empty in the project properties. The program I'm trying to run uses readonly struct, which is part C# 7.2.
Could you please guide me .Net Framework version has C# 7.2?
Language features are independent of .Net version (Framework/Core/Standard).
You will need to use a compiler that understands the newer language features. Assuming you're using Visual Studio 2017, you should update to latest version.
By default C# projects in Visual Studio use the latest major release of the language (which would be 7.0 as of this writing). To change this, open up the project's properties, select the Build page, click Advanced..., and under General set Langauge Version to "C# 7.2".
Per phuzi's comment mentioning this question, you might need to update to the latest Visual Studio in order to see this option.
I'm trying to select target framework from the solution explorer, however all I can see is ".NET Standard 1.0" to 2.0 as available target. I've updated VS to the latest version (15.7.4) and have selected ".NET Desktop Development" workload in the installer. .NET 4-4.6 dev tools also already installed. So why can't I select them?
You've created a ".NET Standard" project and those are the only currently existing versions of the .NET Standard.
It sounds like what you want to create is a "standard" .NET project which is any of the options found under Windows Desktop in the New Project dialog (though none are by that name). This will give you the option of selecting which version of the .NET Framework you want to code against:
Dears, I don't see the option for targeting netcoreapp when I want to create a new project. I've already installed framework and sdk but I still don't see it in the list. Please check screenshot attached.
What should I do else to be able to target net core framework?
UPDATE:
Actually, I need to retarget Unit test project to netcoreapp1.1. How can I do this? I don't see netcoreapp option in the project properties "Target Framework" list.
You don't need to be concerned by this option. Go to the template ".Net Core" and choose the template that you are interested for.
The target option will be define in the project.json (if your are using .net core 1.0 in project.json or .csproj if version >).
But, have a look on the official documentation to have a better picture of it https://learn.microsoft.com/en-us/dotnet/core/
I tried to open a script in VS2015 from Unity 5.6.
For some reasons, this popup shows up and I click the first option and change the target to .Net Framework 4.5.2 and everything builds and works as expected.
However, every time I made changes in the Unity editor and switched back to Visual Studio, this dialog pops up again.
When I looked into the csproj files, I can see that, after I made changes in the Unity editor, I see this:
<TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkProfile>Unity Full v3.5</TargetFrameworkProfile>
Then after I selected "Change the target to .NET Framework 4.5.2"
I see this:
<TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
It seems that the Unity editor is configured to change the .Net Framework to 4.5.
I tried to install .Net Framework 4.5 but it is already installed.
Is there any way I can either use .Net 4.5 in Visual Studio or change the target framework in Unity such that this dialog won't pop up again?
Before you do anything complicated, try this:
Open Edit>Project Setting>Player
Click Other Setting, go to Configuration, if the scripting runtime version is .NET 3.5, change it to .NET 4.x.
This not only fixed the warning, it also got back VS intellisense and the MathNet.Numerics can now be installed properly.
If this does not work, then try this link project-target-framework-not-installed.
In the Unity roadmap is stated that support for .net 4.6 will be added arround july 2017. The beta is out allready.
Scripting Runtime Upgrade (Preview)
Upgrade Mono and IL2CPP .NET runtimes to support the latest .NET functionality and APIs. This includes access to C# 6 and the .NET 4.6.x class library profile.
Currently Unity is only compatible with .net 3.5 but here is an workaround which may help.
If you have any of the .NET Framework v4.6 series allready installed you only need to install the Visual Studio 2015 Tools for Unity to be able to use the project without conversions.
I have a project that targets both .Net 2.0 and .Net 4.5. I built+published it successfully in Visual Studio 2013. The .Net configuration in the .csproj file still says
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
Yet, when I open the project in VS 2015, it targets .Net 4.5.
I have 2.0 available in the Target Framework dropdown:
when I click ".Net Framework 2.0" it gives me a popup saying
Changing the target framework requires that the current project be closed and then reopened.
Any unsaved changes within the project will be automatically saved.
Changing Target Framework my require manual modification of project files in order to build.
Are you sure you want to change the Target Framework for this project?
When I click yes, the target framework goes back to 4.5 and nothing else happens.
I've tried reopening the project and VS, with no luck.
I've tried running the .Net 3.5 installer (which apparently includes 2.0), but it says I need to use "Turn Windows Features on/off"
I've ensured the .Net 3.5 Windows Feature is enabled.
And now I'm out of ideas. Has anyone else encountered this?
Running Windows 7.
In case, the .NET Framework 2.0 is corrupted, use the .NET Framework setup verification tool: https://blogs.msdn.microsoft.com/astebner/2013/11/06/net-framework-setup-verification-tool-and-cleanup-tool-now-support-net-framework-4-5-1/ to verify and once it found any corrupted, you can use the .NET Framework Repair Tool: https://www.microsoft.com/en-us/download/details.aspx?id=30135 to repair it.
Or under ‘Turn Windows Features on or off’, uncheck .NET Framework 3.5 (includes .NET 2.0 and 3.0), then check it.
As Hans Passant mentions in the comments, I apparently(?) edited the .csproj to use different frameworks for different configurations. I swear this didn't cause any issues in VS 2013.
But in any case, I verified using ILSpy that the .dll being generated is .Net 2.0, even though the dropdown says 4.5. So I guess all's well that ends well?