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.
Related
I've inherited a set of build scripts which currently look inside the .sln file, work out what version of Visual Studio they were created with, and then call the version of MSBuild associated with that version of VS.
Is that necessary? Or will the latest version of MSBuild compile older solutions/projects?
Can newer versions of MSBuild compile older C# solutions?
The simple answer is yes.
When building the project from Visual Studio, Visual Studio will call devenv.exe to build the project, then devenv calls msbuild to perform the build.
As per official document Port, Migrate, and Upgrade Visual Studio Projects:
Each new version of Visual Studio generally supports most previous types of projects, files, and other assets. You can work with them as
you always have, and provided that you don't depend on newer features,
Visual Studio preserves backwards compatibility with previous versions
like Visual Studio 2015, Visual Studio 2013, and Visual Studio 2012.
Support for some types change over time, however. A newer version of Visual Studio may no longer support certain types, or require that
they be migrated and updated such that they're no longer
backwards-compatible.
So the latest version of MSBuild supports most previous types of older solutions/projects except those no longer support by the newer version of MSBuild.
Is the program name that was used to build the assembly written into the assembly available anywhere in the MSIL code?
Visual Studio doesn't build anything - Visual Studio uses MSBuild to do its building1:
Visual Studio hosts MSBuild to load and build managed projects.
In fact you can build MSIL code without Visual Studio by downloading Microsoft Build Tools:
If you don't have Visual Studio installed on your computer, you can use Build Tools 2013 to build managed applications. The Visual Basic and C# compilers are also included in this download. (In earlier versions, these tools were included in the stand-alone .NET Framework.)
Any compiler which satisfies the ECMA 335 standard can compile valid Common Language Infrastructure (CLI) applications - the Mono C# compiler is one such example.
In other words, I don't think it's possible to obtain information about the Visual Studio version from the assembly.
Unless some additional metadata is added to the assembly by Visual Studio (I don't think it is), to find out what version of Visual Studio built a specific assembly, you'd have to do something like adding your own custom attributes to the assembly, which you could then use reflection to retrieve.
Obviously, you can rule out earlier versions of Visual Studio based on the .NET version that the assembly targets (e.g. Visual Studio 2012 was the first to support .NET 4.5).
This table is compiled from the Wikipedia article for Visual Studio:
.NET Min Visual
Studio version
1.0 2002 (7.0)
1.1 2003 (7.1)
2.0 2005 (8.0)
3.0 2005 (8.0)
3.5 2008 (9.0)
4.0 2010 (10.0)
4.5 2012 (11.0)
4.5.1 2012 (11.0)
4.5.2 2012 (11.0)
4.6 2015 (14.0)
1 Visual Studio 2015 and above, by default, uses the new Roslyn compiler to compile.
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
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!
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)