Creating a web application project using MSBuild from the command line on 64-bit: file with missing targets

Building a solution containing a web application project using MSBuild from powershell, like this:

msbuild "/p:OutDir=$build_dir\" $solution_file 

Works fine for me on a 32-bit, but on a 64-bit machine, I ran into this error:

error MSB4019: The imported project "C: \ Program Files \ MSBuild \ Microsoft \ VisualStudio \ v9.0 \ WebApplications \ Microsoft.WebApplication.targets" was not found. Verify that the path in the declaration is correct and that the file exists on disk.

I am using Visual Studio 2008 and powershell v2. The problem is already registered here and here . Mostly on a 64-bit VS installation, the Microsoft.WebApplication.targets files needed by MSBuild are located in the Program Files (x86) directory and not in the Program Files directory, but MSBuild does not recognize this and therefore looks in the wrong place.

Two solutions that I still are not perfect:

  • Manually copy the file to the 64-bit Program Files (x86) file in the Program Files. This is a bad decision - every developer will have to do it manually.
  • Manually edit the csproj file so that MSBuild looks in the right place. Again, not perfect: I would prefer not to require that everyone in 64-bit language manually edit csproj files in each new project.

eg.

 <Import Project="$(MSBuildExtensionsPathx86)\$(WebAppTargetsSuffix)" Condition="Exists('$(MSBuildExtensionsPathx86)\$(WebAppTargetsSuffix)')" /> 

Ideally, I want MSBuild to be able to import the target file to the right place from the command line, but I cannot figure out how to do that . Any solutions?

+4
source share
2 answers

This should work without any changes on a 64-bit machine if you run msbuild from the 32-bit prompt. Given this test file:

 <Project DefaultTargets="Test" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5"> <Target Name="Test"> <Message text="$(MSBuildExtensionsPath)"/> </Target> </Project> 

I get this result from a 32-bit PowerShell request on my x64 system:

 PS> msbuild test.proj /nologo Build started 3/26/2010 9:13:10 AM. Project "C:\temp\test.proj" on node 0 (default targets). C:\Program Files (x86)\MSBuild Done Building Project "C:\temp\test.proj" (default targets). 

This should also not be a problem if you run directly from VS, because VS is a 32-bit application.

+1
source

You have several other alternatives:

Since MSBuild mainly works with environment variables, you can always just change the Program Files to be ProgramFiles (x86) before running msbuild.

 $env:ProgramFiles = ${env:ProgramFiles(x86)} 

This should cause MSBuild to look in the right place.

Another approach I can think of is using Start-Job to start MSBuild from a script. This is rather a general purpose workaround:

 Start-Job { Import-Module YourProject Start-YourMsBuildProject } -RunAs32 

Hope this helps

+2
source

Source: https://habr.com/ru/post/1305212/


All Articles