I'm using Visual Studio 2017 Community on a Windows 10 box.
When I add a .net standard library (just the default code) to my solution the solution builds just fine in Visual studio 2017.
But when I try to build the solution using
&'C:\Program Files (x86)\MSBuild\14.0\Bin\msbuild.exe' C:_Sources\MySolution\MyProject\MyProject.csproj
I get a build error:
error MSB4041: The default XML namespace of the project must be the
MSBuild XML namespace. If t he project is authored in the MSBuild 2003
format, please add
xmlns="http://schemas.microsoft.com/developer/msbuild/2003" to the
element. If the pro ject has been authored in the old 1.0 or
1.2 format, please convert it to MSBuild 2003 format
It looks similar to this bugreport but I'm on windows so this does not seem to apply to me.
the csproj file contents:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.4</TargetFramework>
</PropertyGroup>
</Project>
I tried upgrading it to netstandard1.6 but that didn't help either.
I found out I was using the wrong msbuild version.
The msbuild file resides in a different location now with vs2017
How do I call Visual Studio 2017 RC's version of MSBuild from a BAT file?
Related
I have a project which was written by using C#.What i want to do is to learn MSBuild version of the project.I opened the project in Visual Studio 2019.
I found a csproj file on project and It contains these lines
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
As I understand from Lex li answer project build version 15.0 so I should build it visual studio 2017.Am i right? I opened the project in visual studio 2019.
You can right click on the project -> unload it -> edit it
you will find all the relevant information related with the project and build.
then again Reload the project.
Here this link might help you.
Walkthrough: Use MSBuild
I have two projects: NET Standard class library and regular NET Framework web application. Web application references class library.
I use Visual Studio 2017 Preview.
When I try to build the solution with Cake using MSBuild command I get the unsupported project message:
error MSB4041: The default XML namespace of the project must be the MSBuild XML namespace. If the project is authored in the
MSBuild 2003 format, please add xmlns="http://schemas.microsoft.com/developer/msbuild/2003" to the <Project> element. If the project has been authored in the old 1.0 or 1.2 format, please convert it to MS
Build 2003 format.
If I try to use DotNetCoreBuild I get:
error MSB4019: The imported project "C:\Program Files\dotnet\sdk\2.0.2-vspre-006949\Microsoft\VisualStu
dio\v10.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
But the solution is built successfully by Visual Studio.
Latest MSBuild version has the targets to build NET Standard libraries. The problem is in Visual Studio Preview installation path: Cake can't find the latest MSBuild.
It will also fail if you will try to specify VS2017 in MSBuildToolVersion.
You have to specify the MSBuild executable manually to make it work with VS Preview.
string msBuildPath = #"c:\Program Files (x86)\Microsoft Visual Studio\Preview\Professional\MSBuild\15.0\Bin\MSBuild.exe";
MSBuild("../NetStdExample.sln", new MSBuildSettings {
Verbosity = Verbosity.Minimal,
ToolPath = msBuildPath
});
Update by #Gary Ewan Park: there is a tool for determining latest VS install.
I developed a net core class library using Net Core "1.0.0-preview2-003131" version. Currently using VS2015.
But as this should be released soon, I want to move it to "1.0.1".
I installed this update: .NET Core 1.0.4 (https://github.com/dotnet/core/releases/tag/1.0.4)
When I change the version in my global.json I get this error:
Severity Code Description Project File Line Suppression State
Error MSB4019 The imported project "C:\Program Files\dotnet\sdk\1.0.1\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Props" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
So I read that doing "dotnet migrate" it changes my project from xproj to csproj, and the problem should be solved.
But doing that, my csproj doesn't load properly, showing error:
The default XML namespace of the project must be the MSBuild XML namespace. If the project is authored in the MSBuild 2003 format, please add xmlns="http://schemas.microsoft.com/developer/msbuild/2003" to the element. If the project has been authored in the old 1.0 or 1.2 format, please convert it to MSBuild 2003 format.
You need to upgrade to Visual Studio 2017 to use the csproj format that dotnet-migrate generates. .NET Core CLI does not support xproj or project.json.
Or, you can use Visual Studio Code with the C# extension on either project.json or csproj projects, but not both.
Today I installed the .NET Framework 4.5 on my machine expecting to be able to use it from Visual Studio 2010, since it's just a minor update that should't pose problems for Visual Studio 2010. Unfortunately I am not, even manually removing certain 4.0 and adding the corresponding 4.5 assemblies resulted in the original 4.0 assemblies still being referenced in the project.
Is it possible to target version 4.5 from Visual Studio 2010 and if yes, how? I'd really like to use the ribbons...
Each version of Visual Studio prior to Visual Studio 2010 is tied to a specific .NET framework. (VS2008 is .NET 3.5, VS2005 is .NET 2.0, VS2003 is .NET1.1) Visual Studio 2010 and beyond allow for targeting of prior framework versions but cannot be used for future releases. You must use Visual Studio 2012 in order to utilize .NET 4.5.
There are pretty limited scenarios that I can think of where this would be useful, but let's assume you can't get funds to purchase VS2012 or something to that effect. If that's the case and you have Windows 7+ and VS 2010 you may be able to use the following hack I put together which seems to work (but I haven't fully deployed an application using this method yet).
Backup your project file!!!
Download and install the Windows 8 SDK which includes the .NET 4.5 SDK.
Open your project in VS2010.
Create a text file in your project named Compile_4_5_CSharp.targets with the following contents. (Or just download it here - Make sure to remove the ".txt" extension from the file name):
<Project DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Change the target framework to 4.5 if using the ".NET 4.5" configuration -->
<PropertyGroup Condition=" '$(Platform)' == '.NET 4.5' ">
<DefineConstants Condition="'$(DefineConstants)'==''">
TARGETTING_FX_4_5
</DefineConstants>
<DefineConstants Condition="'$(DefineConstants)'!='' and '$(DefineConstants)'!='TARGETTING_FX_4_5'">
$(DefineConstants);TARGETTING_FX_4_5
</DefineConstants>
<PlatformTarget Condition="'$(PlatformTarget)'!=''"/>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<!-- Import the standard C# targets -->
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- Add .NET 4.5 as an available platform -->
<PropertyGroup>
<AvailablePlatforms>$(AvailablePlatforms),.NET 4.5</AvailablePlatforms>
</PropertyGroup>
</Project>
Unload your project (right click -> unload).
Edit the project file (right click -> Edit *.csproj).
Make the following changes in the project file:
a. Replace the default Microsoft.CSharp.targets with the target file created in step 4
<!-- Old Import Entry -->
<!-- <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> -->
<!-- New Import Entry -->
<Import Project="Compile_4_5_CSharp.targets" />
b. Change the default platform to .NET 4.5
<!-- Old default platform entry -->
<!-- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> -->
<!-- New default platform entry -->
<Platform Condition=" '$(Platform)' == '' ">.NET 4.5</Platform>
c. Add AnyCPU platform to allow targeting other frameworks as specified in the project properties. This should be added just before the first <ItemGroup> tag in the file
<PropertyGroup Condition="'$(Platform)' == 'AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
.
.
.
<ItemGroup>
.
.
.
Save your changes and close the *.csproj file.
Reload your project (right click -> Reload Project).
In the configuration manager (Build -> Configuration Manager) make sure the ".NET 4.5" platform is selected for your project.
Still in the configuration manager, create a new solution platform for ".NET 4.5" (you can base it off "Any CPU") and make sure ".NET 4.5" is selected for the solution.
Build your project and check for errors.
Assuming the build completed you can verify that you are indeed targeting 4.5 by adding a reference to a 4.5 specific class to your source code:
using System;
using System.Text;
namespace testing
{
using net45check = System.Reflection.ReflectionContext;
}
When you compile using the ".NET 4.5" platform the build should succeed. When you compile under the "Any CPU" platform you should get a compiler error:
Error 6: The type or namespace name 'ReflectionContext' does not exist in
the namespace 'System.Reflection' (are you missing an assembly reference?)
FYI, if you want to create an Installer package in VS2010, unfortunately it only targets .NET 4. To work around this, you have to add NET 4.5 as a launch condition.
Add the following in to the Launch Conditions of the installer (Right click, View, Launch Conditions).
In "Search Target Machine", right click and select "Add Registry Search".
Property: REGISTRYVALUE1
RegKey: Software\Microsoft\NET Framework Setup\NDP\v4\Full
Root: vsdrrHKLM
Value: Release
Add new "Launch Condition":
Condition: REGISTRYVALUE1>="#378389"
InstallUrl: http://www.microsoft.com/en-gb/download/details.aspx?id=30653
Message: Setup requires .NET Framework 4.5 to be installed.
Where:
378389 = .NET Framework 4.5
378675 = .NET Framework 4.5.1 installed with Windows 8.1
378758 = .NET Framework 4.5.1 installed on Windows 8, Windows 7 SP1, or Windows Vista SP2
379893 = .NET Framework 4.5.2
Launch condition reference: http://msdn.microsoft.com/en-us/library/vstudio/xxyh2e6a(v=vs.100).aspx
I have been struggling with VS2010/DNFW 4.5 integration and have finally got this working. Starting in VS 2008, a cache of assemblies was introduced that is used by Visual Studio called the "Referenced Assemblies". This file cache for VS 2010 is located at \Reference Assemblies\Microsoft\Framework.NetFramework\v4.0. Visual Studio loads framework assemblies from this location instead of from the framework installation directory. When Microsoft says that VS 2010 does not support DNFW 4.5 what they mean is that this directory does not get updated when DNFW 4.5 is installed. Once you have replace the files in this location with the updated DNFW 4.5 files, you will find that VS 2010 will happily function with DNFW 4.5.
From another search. Worked for me!
"You can use Visual Studio 2010 and it does support it, provided your OS supports .NET 4.5.
Right click on your solution to add a reference (as you do). When the dialog box shows, select browse, then navigate to the following folder:
C:\Program Files(x86)\Reference Assemblies\Microsoft\Framework\.Net Framework\4.5
You will find it there."
I have a Visual Studio 2008 project that is a Smart Device project targeting a .NET 3.5 Compact Framework Windows CE device and it currently references a 3.5 class library project.
What I would like to do is be able to add the class library into a Visual Studio 2012/2013 solution without "migrating" it.
For example the structure is currently:
VS2008 Solution
Smart Device Project
Class Library Project
I want to have is:
A VS2008 Solution
Smart Device Project
Class Library Project
A VS2013 Solution
Class Library Project
ASP.NET MVC Project
The result of this would be that I can work on the Smart device project in VS2008 and add classes to the Class Library Project, and then be able to open the VS2013 solution file and have those new classes available.
When I look at the difference between a 2008 Class Project and a 2013 Class Project csproj files, the only thing that really is different is the ToolsVersion on the Project element (http://msdn.microsoft.com/en-us/library/bcxfsh87.aspx).
In VS2008 the ToolsVersion is 3.5, but in VS2013 its 12.0.
I've attempted to make the ClassLibraryProject switch between 3.5 and 12.0 for the ToolsVersion with the following:
<Project ToolsVersion="$(ProjectToolsVersion)">
<Choose>
<When Condition="'$(VisualStudioVersion)' != ''">
<PropertyGroup>
<ProjectToolsVersion>12.0</ProjectToolsVersion>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<ProjectToolsVersion>3.5</ProjectToolsVersion>
</PropertyGroup>
</Otherwise>
</Choose>
<!-- other project stuff -->
</Project>
I can open this fine in VS2013, but when I open it in VS2008 it says:
Unable to read the project file 'ClassLibraryProject.csproj'.
C:\Test\ClassLibraryPorject.csproj: The tools version "$(ProjectToolsVersion)" is unrecognized.
Please Note: I am not able to migrate the entire project to VS2013 because VS2013 does not support Smart Device projects.
VS2008 which uses MSBuild 3.5 should be able to handle ToolsVersion 12, as in that case it automatically falls back to ToolsVersion 3.5.
Thus, you should migrate the class library project in VS2013, and it should be able to work still in the VS2008 solution without any modification.
VS2008 and MSBuild 3.5 gives you the error, because Choose is evaluated later than Project, so what you define in Choose (aka ProjectToolsVersion) cannot be used in Project.