Visual Studio 2010 Command Line with Framework 2.0 - c#

Before, I was using VS 2008 command prompt and when I do
clrver
I got
Versions installed on the machine:
v1.1.4322
v2.0.50727
Now with Visual Studio 2010 command prompt I get :
Versions installed on the machine:
v1.1.4322
v2.0.50727
v4.0.30319
I want to know if there is a way to compile my C# code with the VS 2010 command line using the Framework 2.0 and not 4.0
-- Edit --
Is there another way than going in the properties of the project?

Use MSBuild command line and pass the ToolsVersion (2.0,3.0,3.5,4.0) and TargetFrameworkVersion (v2.0,v3.0,v3.5,v4.0) properties:
msbuild your.sln /p:TargetFrameworkVersion=v2.0;ToolsVersion=3.5
The UI option is described here.

You can change the targeted framework in your project settings.
http://msdn.microsoft.com/en-us/library/bb398202.aspx
(I do not yet have VS 2010 on my work machine, so I can't test whether or not support extends to .NET 2.0, though I believe it does)

Related

MSBuild update, where dos this come from?

Here is the context :
2 persons are working on a WPF application (me and a colleague)
we both use the VS 2017 (i have the version 15.6.6 he has the version 15.6.4)
we are both using the most recent and fully updated .NET Framework
we are using MSI installation system to deploy our WPF application + Win services
we are using WIX to package all this
But something strange happened: when I generate the installer, the netstandard.dll version deployed is the 4.6.25908.2, and when he generates the installer, the netstandard.dll is the 4.6.26011.1
After some research, we discover that this dll is coming from MSBUILD, and by checking in the "Developer Command Prompt for VS 2017", using the "msbuild" command :
- my version is 15.5.180.xxxx
- his version is 15.6.6.xxxx
My question is pretty simple, what is responsible for updating msbuild package?
Obviously, not VS or .Net Framework
I have found some nugget package to add to my projects but I don't want this, I want this dll to be updated properly in "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\lib" directory
How can I manage to achieve this?
Ok I found what was going on and there was no way to find out with what I posted.
This is the story :
I installed VS 2017 Pro with a license
I tried VS 2017 Enterprise for sometimes with a trial license
VS 2017 setup made 2 distinct installations
After the trial license expired, I was still using then Enterprise installation downgraded to a Pro version
The Enterprise version was up to date but not the original Pro version
Conlusion: by updating the VS 2017 Pro version specifically, it solved my problem
#Hans Passant: the MSBUILD was indeed updated with VS 2017, but for some reason, I don't really understand, I have to update both Pro and Enterprise version to 15.6.6.xxxx in order to update MSBUILD properly

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.

Using 2013 msbuild in program with Project.Build

Our tests use Microsoft.Build.Evaluation.Project.Build to build projects.
Works fine for VS 2010 & 2012. Trouble is in VS 2013, it picks up msbuild from
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
ver 4.0.30319.18408
instead of from VS 2013
C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe
ver 12.0.21005.1
Is there any method to ask it to pick up the VS 2013 msbuild?
May be adding to the .proj file or setting an environment value before calling the build method?
MSBuild and its Toolset now Version with Visual Studio
We plan to evolve our build tools with each version of Visual Studio from now on. Each release of the Micrsoft® Build Tools will have a new version of MSBuild, the VB/C# Compilers, and Toolset. They will all version together. Visual Studio will use its corresponding version of MSBuild exclusively. For instance, Visual Studio 2013 will exclusively use MSBuild 2013 and ToolsVersion=”12.0”. To align with Visual Studio’s versioning we have updated MSBuild’s assembly version from 4.0 to 12.0 as well.
And a link to the visual studio team page, with a few additional defaults to check
http://blogs.msdn.com/b/visualstudio/archive/2013/07/24/msbuild-is-now-part-of-visual-studio.aspx
however 4.0 and version 12 are the same; re-versioned to support the visual studio version number format
from:
http://en.wikipedia.org/wiki/.NET_Framework_version_history#.NET_Framework_4.5
//Quote//
.NET Framework 4.5 was released on 15 August 2012.,[27] a set of new or improved features were added into this version.[28] The .NET Framework 4.5 is only supported on Windows Vista or later.[29][30] The .NET Framework 4.5 uses Common Language Runtime 4.0, with some additional runtime features.[31]
//End Quote
Since 4.5 is an "upgrade" to the 4.0 library......."C:\Windows\Microsoft.NET\Framework\v4.0.30319\" is where I would expect it to find its version of MsBuild.exe.
Are the MSBuild.Exe (that you list) different?
You could experiment with overriding the
<Message Text=" MSBuildBinPath = $(MSBuildBinPath)" />
property.

.Net framework 4.5 Installed , still getting the error Project is Incompatiable

I have installed .NET framework 4.0 on my system , but when I open my project on VS 2010 , still getting the message ,
This Project is incompatiable with the current version of Visual Studio
Any Idea? I don not want to change the target framework to v4.0 in .csproject.
The error you are getting is not about an incompatible .NET framework version, it is about an incompatible Visual Studio version!
Visual Studio project versions are not linked to .NET versions. A Visual Studio 2008 project can target .NET 2.0 up to 3.5, but still you can't open a VS 2008 project with Visual Studio 2005, even though Visual Studio 2005 can create .NET 2.0 projects, too.
Having the latest .NET framework on your machine does not guarantee that you can open projects with the latest Visual Studio version in an older Visual Studio.
You can simply not downgrade Visual Studio projects easily. There are posts describing how to to it by modifying the project files, etc., but in general you can only upgrade projects using the wizard that's automatically opened by Visual Studio.
As I know you can't target .NET 4.5 with VS2010 the same way you couldn't target .NET 4.0 with VS2008. You will need to install VS2012 if you want to target .NET 4.5.
EDIT
found this answer but haven't tried it by myself

Multi-targeting .NET Framework 4 and Visual Studio 2012

I have installed Visual Studio 2012 Professional on my machine. I don't have Visual Studio 2010 installed, but I want to keep developing my applications using .NET Framework 4, but I don't have this option on my Visual Studio 2012. Look at the image:
I don't know what can I do to fix this problem, because I click on "More Frameworks..." link and try to install the Multi-Targeting for .NET 4.0.3 (installed on my machine), but it does not work. It says that this version of framework is still installed. What can I do to fix this problem?
Obs: I have lots of projects in C# and VB.NET with .NET 4.0, and I need to keep these projects with new projects on .NET 4.0.
I solved the problem doing these tasks:
Uninstall the Visual Studio 2012
Uninstall any reference for the .NET Framework 4.0 or 4.5
Clean the register with a tool like Glary Utilities and restart the computer
Install the .NET Framework 4.0 and install Microsoft Multi-Targeting for .NET Framework 4.
Install Visual Studio 2012 again
You fixed your problem, but it's likely that .NET Framework 4 Targeting Pack (not to be confused with the .NET Framework itself) failed to install for some reason. Did you get a warning at the end of the Visual Studio installation? Either way, in the future, a repair install of Visual Studio 2012 should have fixed the problem (Add or Remove Programs -> Microsoft Visual Studio [Edition] 2012 -> Change -> Repair).
I think that your issue is probably some mishap with the installation of .NET Framework. I installed Visual Studio 2012 Beta and have all kind of troubles with compatibility between framework versions. The only remedy was reinstalling Visual Studio, including .NET Framework.
Check out How to: Target a Version of the .NET Framework (MSDN).
After creating new a project, go to its properties (select your project in Solution Explorer then right click and select properties) and select the target framework!

Categories

Resources