开发者

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

开发者 https://www.devze.com 2023-04-01 17:45 出处:网络
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:

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 bui开发者_StackOverflow中文版lding 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号