I have an ASP.NET MVC Web Application created in VS2013 and use TeamCity 8.1 for CI.
I'm trying to restore my Nuget packages before building my Visual Studio solution using a Nuget Pack build step in TeamCity and get this error:
The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets"
was not found. Confirm that the path in the <Import> declaration is correct
It's trying to access the targets in the wrong path because I use version 12.0 and not 10.0.
My solution file starts with this lines:
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30501.0
The project file of my MVC project created in VS2013 have a this declaration of VisualStudioVersion
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
...
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
I suppose the declaration of VisualStudioVersion is the reason to why the build step of restoring Nuget packages is accessing the wrong folder. But I'm not sure what the condition in property VisualStudioVersion is evaluated to.
I've tried to create an Environment variable for VisualStudioVersion and set it to 12.0 but that did not work.
The strange thing is if I disable the Nuget Pack step in TeamCity the build step seems to find the correct path
Starting: C:\TeamCity\buildAgent\plugins\dotnetPlugin\bin\JetBrains.BuildServer.MsBuildBootstrap.exe /workdir:C:\TeamCity\buildAgent\work\17b24c83f45b721d "/msbuildPath:C:\Program Files (x86)\MSBuild\12.0\bin\MSBuild.exe"
Related
I have merged Angular 2 CLI app with .NET MVC application. I use ng commands to build the application and VSCode for Angular and Visual Studio for .NET Code. I want to disable the Typescript compilation by Visual Studio so that Visual Studio should not care about typescript errors.
To Disable typscript compilation by Visual Studio I have edited .csproj project file and added below code (refer)
<PropertyGroup>
<!-- Disables TypeScript compilation -->
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
</PropertyGroup>
Comment line below and add new one
<!--<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets')" />-->
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="False" />
Its works fine, but some time start giving typescript errors in visual studio as below(screenshot).
To make errors go away, I do which sometime works:
Clean Solution and Build
Restart Visual Studio
I don't know any better solution for this, any suggestions ?
I am creating a nuget-package with /t:pack in my TFS-Build. I can't the use Nuget-Pack-Step, because I am using
<TargetFramework>netstandard2.0</TargetFramework>
How can I apply my AssemblyVersion on the Nuget-Package? Because my Assembly-Version is right, but my Nuget version always remains 1.0.0.0.
Note I am using a C# file for my assembly information instead of the .csproj file.
Is there any possibility to it?
Want to share that link.
The MSBuild-integrated Pack target reads its value from MSBuild properties inside the project (PackageVersion to be specific, which is defaulted from Version, which in turn is defaulted to VersionPrefix which in turn may be suffixed by VersionSuffix).
There is out-of-the-box support for reading this value from an assembly attribute since the new project format is meant to generate these assembly attributes from the same configuration that determines NuGet package metadata.
However, you can extend the build by adding a custom target to the csproj file that reads the built assembly's identity during msbuild /t:Pack:
<Project>
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateNuspecDependsOn>$(GenerateNuspecDependsOn);ReadPackageVersionFromOutputAssembly</GenerateNuspecDependsOn>
</PropertyGroup>
<Target Name="ReadPackageVersionFromOutputAssembly" DependsOnTargets="Build">
<GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
<Output TaskParameter="Assemblies" ItemName="PackAssembly" />
</GetAssemblyIdentity>
<PropertyGroup>
<PackageVersion>%(PackAssembly.Version)</PackageVersion>
</PropertyGroup>
</Target>
</Project>
Note that this target will only run on the "full MSBuild", that is msbuild.exe on windows (visual studio developer command prompt) or mono 5.2+ on linux/Mac. This currently does not work for dotnet pack (.NET Core version of MSBuild). UPDATE: This will now work in .NET SDKs 2.1.* and higher since the GetAssemblyIdentity task has been added to the cross-platform version of msbuild in 2018.
With current version of MSBuild it is possible to specify PackageVersion parameter:
msbuild ProjectName.csproj -t:Pack -p:PackageVersion=1.2.3
I cloned the ASP.NET Core SignalR Repo locally, and try opening the solution from within the following environment.
IDE
Microsoft Visual Studio Enterprise 2015
Version 14.0.25431.01 Update 3
Microsoft .NET Framework
Version 4.6.01055
DOT NET CLI
λ dotnet --info
.NET Command Line Tools (1.0.0-preview2-1-003177)
Product Information:
Version: 1.0.0-preview2-1-003177
Commit SHA-1 hash: a2df9c2576
Runtime Environment:
OS Name: Windows
OS Version: 6.1.7601
OS Platform: Windows
RID: win7-x64
I end up seeing a lot of these kinds of error messages:
..\Repos\SignalR\src\Microsoft.AspNetCore.SignalR\Microsoft.AspNetCore.SignalR.csproj
: 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. ..\Repos\SignalR\src\Microsoft.AspNetCore.SignalR\Microsoft.AspNetCore.SignalR.csproj
I want to know how to fix this the correct way.
The projects you are trying to open are in the new .NET Core csproj format. This means you need to use Visual Studio 2017 which supports this new format.
For a little bit of history, initially .NET Core used project.json instead of *.csproj. However, after some considerable internal deliberation at Microsoft, they decided to go back to csproj but with a much cleaner and updated format. However, this new format is only supported in VS2017.
If you want to open the projects but don't want to wait until March 7th for the official VS2017 release, you could use Visual Studio Code instead.
I ran into this issue while opening the Service Fabric GettingStartedApplication in Visual Studio 2015. The original solution was built on .NET Core in VS 2017 and I got the same error when opening in 2015.
Here are the steps I followed to resolve the issue.
Right click on (load Failed) project and edit in visual studio.
Saw the following line in the Project tag: <Project Sdk="Microsoft.NET.Sdk.Web" >
Followed the instruction shown in the error message to add xmlns="http://schemas.microsoft.com/developer/msbuild/2003" to this tag
It should now look like:
<Project Sdk="Microsoft.NET.Sdk.Web" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
Reloading the project gave me the next error (yours may be different based on what is included in your project)
Saw that None element had an update attribute as below:
<None Update="wwwroot\**\*;Views\**\*;Areas\**\Views">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>
Commented that out as below.
<!--<None Update="wwwroot\**\*;Views\**\*;Areas\**\Views">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>-->
Onto the next error: Version in Package Reference is unrecognized
Saw that Version is there in csproj xml as below (Additional PackageReference lines removed for brevity)
Stripped the Version attribute
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" />
I now get the following:
Bingo! The visual Studio One-way upgrade kicked in! Let VS do the magic!
The Project loaded but with reference lib errors.
Fixed the reference lib errors individually, by removing and replacing in NuGet to get the project working!
Hope this helps another code traveler :-D
#DavidG's answer is correct, but I would like to add that if you're building from the command line, the equivalent solution is to make sure that you're using the appropriate version of msbuild (in this particular case, it needs to be version 15).
Run msbuild -version to see which version you're using or where msbuild to check which location the environment takes the executable from and update (or point to the right location of) the tools if necessary.
Download the latest MSBuild tool from here.
If getting this error trying to build .Net Core 2.0 app on VSTS then ensure your build definition is using the Hosted VS2017 Agent queue.
I was getting the same messages while I was running just msbuild from powershell.
dotnet msbuild "./project.csproj" worked for me.
if the project is not a big ,
1- change the name of folder project
2- make a new project with the same project (before renaming)
3- add existing files from the old project to the new project (totally same , same folders , same names , ...)
4- open the the new project file (as xml ) and the old project
5- copy the new project file (xml content ) and paste it in the old project file
6- delete the old project
7- rename the old folder project to old name
I had the same problem and solved it by using dotnet instead of msbuild.
I have MVC 5 application which is using RazorGenerator.MVC and RazorGenerator.MsBuild. Because of that my MvcBuildViews is set to false, because it is no longer required. The application is .NET 4.5 one in Visual Studio 2012.
When I'm publishing my application with web publish tool (right click on MVC project -> Publish), I'm using option to pre-compile during publishing.
Everything is working very well when I'm using Any CPU or x32 Platform. However when I'm trying to publish x64 application I have an issue with aspnet_compiler.
It is always trying to use: *C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe* one instead of 64 version so my application cannot be published with x64 platform.
The only place I found I can change path is under MvcBuildViews target, but becuase it is always false for me it will never hit this target and AspNetCompiler ToolPath cannot be used.
I'd like to know from where (which targets file or tasks file) contains that path? I've searched all targets I believe and couldn't find from where is taken.
Open the csproj file of the project in your favourite text editor.
Locate:
<MvcBuildViews>true</MvcBuildViews>
Add the following below it:
<AspNetToolPath Condition=" '$(Platform)' == 'x64'">$(windir)\Microsoft.NET\Framework64\v4.0.30319</AspNetToolPath>
Locate:
<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'" >
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>
Amend the AspNetCompiler line as follows:
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" ToolPath="$(AspNetToolPath)" />
For Visual Studio 2013, the solution can be found here: Configure Visual Studio 2013 to allow ASPNETCOMPILER to precompile using the x64 compiler (thanks to Nitin)
Shortcut:
Add the following xml in the Project/PropertyGroup xml tag to the publish profile (located in the Properties\PublishProfiles directory of your project).
<AspnetCompilerPath>C:\Windows\Microsoft.NET\Framework64\v4.0.30319</AspnetCompilerPath>
I have an ASP.NET MVC project whose project file I modified to have the following properties so that it would create a deploy package in a subdirectory of the output folder when it builds in the Release configuration:
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DeployTarget>Package</DeployTarget>
<DeployOnBuild>true</DeployOnBuild>
<CreatePackageOnPublish>true</CreatePackageOnPublish>
</PropertyGroup>
When I build the project from the command line as follows:
msbuild projectname.csproj /p:Configuration=Release
Then, the deploy files are packaged up correctly in a subdirectory underneath the Release output. However, if I build the project from within Visual Studio the deploy files and packages aren't created, even if I have the configuration set to Release.
Is it possible you are not under the any CPU playpen in vs? You could probably remove that all together from the conditional.