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 32-bit, but on a 64-bit machine I am running into this error:
error MSB4019: The imported project "C:\\Program Files\\MSBuild\\Microsoft\\VisualStudio\\v9.0\\WebApplications\\Microsoft.WebApplication.targets" was not found. Confirm 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 has already been documented here and here . Basically on 64-bit install of VS, the Microsoft.WebApplication.targets needed by MSBuild is in the Program Files(x86) dir, not the Program Files dir, but MSBuild doesn't recognise this and so looks in the wrong place.
The two solutions I have so far are not ideal:
eg
<Import Project="$(MSBuildExtensionsPathx86)\$(WebAppTargetsSuffix)" Condition="Exists('$(MSBuildExtensionsPathx86)\$(WebAppTargetsSuffix)')" />
Ideally I want a way to tell MSBuild to import the target file form the right place from the command line but I can't work out how to do that . Any solutions?
You have a couple of other alternatives:
Since MSBuild basically works off of environmental variables, you could always just change Program Files to be ProgramFiles (x86) before you start msbuild.
$env:ProgramFiles = ${env:ProgramFiles(x86)}
This should trick MSBuild into looking in the right place
The other approach I can think of is using Start-Job to run MSBuild from within the script. This is more of a general purpose workaround:
Start-Job {
Import-Module YourProject
Start-YourMsBuildProject
} -RunAs32
Hope this helps
This should work without any modifications on a 64 bit machine IF you run msbuild from a 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 prompt 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 also shouldn't be a problem if you run directly from VS because VS is a 32-bit app.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.