简体   繁体   中英

MSBuild uses .sln when called from PowerShell script but .csproj when called from command line

I've been scratching my head on this one for a while and cannot seem to find anything. I am trying to execute the following:

C:\\Windows\\Microsoft.NET\\Framework\\v3.5\\MsBuild.exe D:\\SourceFiles\\Testing\\AppaloosaDotNet\\AppaloosaDotNet\\AppaloosaDotNet.csproj "/t:_CopyWebApplication;ResolveReferences;publish" /p:ReferencePath=D:\\Builds\\Testing\\LatestBuild\\ /p:OutDir=\\\\ServerName\\D$\\WebContent\\AppaloosaDotNET\\bin\\ /p:WebProjectOutputDir=\\\\ServerName\\D$\\WebContent\\AppaloosaDotNET\\

If I type this command directly into the PowerShell prompt it works fine. However I have created a PowerShell script that makes this call for me and when the script executes, MSBuild moves up one folder and uses the solution file (.sln) to build the project. This causes problems because the targets are not found in the solution file.

If I manually type the command and execute it MSBuild prints out it is building D:\\SourceFiles\\Testing\\AppaloosaDotNET\\AppaloosaDotNET\\AppaloosaDotNET.csproj and the build is fine.

but if I run the script MSBuild prints out it is building D:\\SourceFiles\\Testing\\AppaloosaDotNET\\AppaloosaDotNET.sln and then the build fails because the targets are not found.

I'm sure I'm doing something wrong in my script but cannot figure out what. I have double checked to see that the command executed by the script is the same as I what I type. I even copied the command that is run when running the script and pasted at the prompt and it runs fine so I'm pretty sure the commands are the same. Any ideas?

Could your script be located at the same path as your solution? How exactly are you running your script and where does it reside (if it's not on the same path as solution)? It could be nothing but let's just confirm.

Just an update. I started having more issues with the script but finally have found a solution. I was building the command line using string variables inside the script. Initially the script was executing the command using the & operator. I ended up using the Invoke-Expression command and the problems were solved.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM