如何在 MSBuild WebProjectOutputDir 中留有空格?

发布于 2024-07-25 21:09:40 字数 1072 浏览 7 评论 0原文

我正在尝试从命令行调用 MSBuild。 当我使用没有空格的路径时,一切工作正常,但现在我有一个有空格的路径,并且命令失败。

命令(有效):

"C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe" 
/t:Rebuild "C:\Projects\myProject.csproj" 
/p:OutDir=c:\temp\deploy\funAndGames\Deployment\bin\ 
/p:WebProjectOutputDir=c:\temp\deploy\funAndGames\Deployment\ 
/p:Configuration=Release

然后我添加了引号并将 OutDir 更改为 OutPath(不起作用):

"C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe" 
/t:Rebuild "C:\Projects\myProject.csproj" 
/p:OutPath="c:\temp\deploy\funAndGames\Deployment\bin\" 
/p:WebProjectOutputDir="c:\temp\deploy\funAndGames\Deployment\" 
/p:Configuration=Release

我的目标是这样的(不起作用):

"C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe" 
/t:Rebuild "C:\Projects\myProject.csproj" 
/p:OutPath="c:\temp\deploy\fun and games\Deployment\bin\" 
/p:WebProjectOutputDir="c:\temp\deploy\fun and games\Deployment\" 
/p:Configuration=Release

有关 OutDir/OutPath 和 WebProjectOutputDir 与空格的语法的任何帮助? 是否可以? 如果不是,有人知道原因是什么(由于某些网址没有空格类型吗?)

I am trying to call MSBuild from a command line. Everything was working fine when I was using a path that had no spaces, but now I have a path that has spaces and the command is failing.

Command (works):

"C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe" 
/t:Rebuild "C:\Projects\myProject.csproj" 
/p:OutDir=c:\temp\deploy\funAndGames\Deployment\bin\ 
/p:WebProjectOutputDir=c:\temp\deploy\funAndGames\Deployment\ 
/p:Configuration=Release

I then added quotes and changed OutDir to OutPath (doesn't work):

"C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe" 
/t:Rebuild "C:\Projects\myProject.csproj" 
/p:OutPath="c:\temp\deploy\funAndGames\Deployment\bin\" 
/p:WebProjectOutputDir="c:\temp\deploy\funAndGames\Deployment\" 
/p:Configuration=Release

What I am aiming for is something like this (doesn't work):

"C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe" 
/t:Rebuild "C:\Projects\myProject.csproj" 
/p:OutPath="c:\temp\deploy\fun and games\Deployment\bin\" 
/p:WebProjectOutputDir="c:\temp\deploy\fun and games\Deployment\" 
/p:Configuration=Release

Any help on the syntax around OutDir/OutPath and WebProjectOutputDir with spaces? Is it possible? If it isn't does anyone know what the reason is (due to some Url's not having spaces type thing?)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

阿楠 2024-08-01 21:09:40

刚刚找到了这个老问题的答案。
要处理空格,您应该在所有文件夹上使用转义字符 \。 基本上

/p:OutPath="c:\temp\deploy\fun and games\Deployment\bin\"

应该是这样

/p:OutPath="c:\\temp\\deploy\\fun and games\\Deployment\\bin\\"

,而且它神奇地起作用了!

Just found this out an answer to this old question.
To handle spaces, you should use the escape character \ on all folders. Basically

/p:OutPath="c:\temp\deploy\fun and games\Deployment\bin\"

should be

/p:OutPath="c:\\temp\\deploy\\fun and games\\Deployment\\bin\\"

and magically it works!

來不及說愛妳 2024-08-01 21:09:40

尝试添加 "
前任:

/p:OutPath=""c:\temp\deploy\fun and games\Deployment\bin\""

Try add "
ex:

/p:OutPath=""c:\temp\deploy\fun and games\Deployment\bin\""
挽容 2024-08-01 21:09:40

如果您将 \ 切换到 /,同时使用引号,Msbuild 似乎也可以使用 OutDir 中的空格:

/p:OutDir="c:/temp/deploy/fun and games/out/"
/p:WebProjectOutputDir="c:/temp/deploy/fun and games/Deployment/"

Msbuild also seems to work with spaces in the OutDir if you switch \ to /, while using quotes:

/p:OutDir="c:/temp/deploy/fun and games/out/"
/p:WebProjectOutputDir="c:/temp/deploy/fun and games/Deployment/"
暖阳 2024-08-01 21:09:40

对我来说,工作解决方案是:

/p:SQLCMD="\"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE\""

换句话说:将所有字符串放入引号中(外部引号不会作为值传递给 MSBuild)。

MSBuild 中此属性的值为:“C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE”(带引号)。

For me the working solution is:

/p:SQLCMD="\"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE\""

In other words: Putting all the string into quotes (the external quotes aren't passed as value to MSBuild).

The value inside MSBuild for this property is: "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE" (with the quotes).

宁愿没拥抱 2024-08-01 21:09:40
> "C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe"
> /t:Rebuild
> "C:\Projects\myProject.csproj" 
/p:OutPath="c:\temp\deploy\funAndGames\Deployment\bin\"
----------------------------------------
/p:WebProjectOutputDir="c:\temp\deploy\fun and games\Deployment\"
----------------------------------------

> /p:Configuration=Release

尝试这个。

也可以尝试通过 VSStudio GUI。 然后复制设置& 尝试使用 MS Build。

> "C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe"
> /t:Rebuild
> "C:\Projects\myProject.csproj" 
/p:OutPath="c:\temp\deploy\funAndGames\Deployment\bin\"
----------------------------------------
/p:WebProjectOutputDir="c:\temp\deploy\fun and games\Deployment\"
----------------------------------------

> /p:Configuration=Release

Try this.

Also try via VSStudio GUI. Then copy the settings & try with MS Build.

┼── 2024-08-01 21:09:40

如果开关中有多个参数,则无法通过修复路径来真正“避免”问题。 您可以做的是将开关的参数放在“ some_parameters1 some_parameters2 ”之间。

就像:

<Exec Command="SomeCommand /useMultipleParameterSwitch="value1:blabla1 | value2:blabla2""/>

当然,很大程度上取决于开关的语法,但这对我和我的团队有用。

If you have multiple parameters in a switch you can't really 'avoid' the problem by fixing the path. What you can do is put your parameters of the switch between " some_parameters1 some_parameters2 ".

Something like:

<Exec Command="SomeCommand /useMultipleParameterSwitch="value1:blabla1 | value2:blabla2""/>

Of course a lot depends of the syntax of the switches but that works for me and my team.

安静被遗忘 2024-08-01 21:09:40

要在使用 .proj 文件并且您的路径包含在 $(DeployFolder) 和 $(NuGetExe) 等属性中时执行此操作,您可以使用“"” 像这样:

<Exec Command=""$(NuGetExe)" pack -OutputDirectory "$(DeployFolder)"" />

To do this when using a .proj file and your path is included in properties like $(DeployFolder) and $(NuGetExe), you can use """ like this:

<Exec Command=""$(NuGetExe)" pack -OutputDirectory "$(DeployFolder)"" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文