如何在MSBuild WebProjectOutputDir中设置空格?

时间:2021-12-19 00:07:58

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.

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

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):

然后我添加了引号并将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

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?)

关于OutDir/OutPath和WebProjectOutputDir的语法有什么帮助吗?是可能的吗?如果不是的话,有没有人知道原因是什么(因为一些Url没有空格类型的东西?)

7 个解决方案

#1


20  

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!

神奇的效果!

#2


5  

Try add " ex:

尝试添加“;例:

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

#3


4  

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

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

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

#4


1  

> "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.

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

#5


1  

For me the working solution is:

对我来说,有效的解决方案是:

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

/ p:SQLCMD = " \ " C:\ Program Files \ Microsoft SQL Server \ 100 \ \ Binn \ SQLCMD.EXE \工具”“

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

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

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

该属性的MSBuild内的值是:“C:\程序文件\Microsoft SQL Server\100\Tools\Binn\SQLCMD。”EXE”(引号)。

#6


1  

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 ".

如果你在一个开关中有多个参数,你不能通过修正路径来“避免”这个问题。您可以做的是将开关的参数放在“some_parameters1 some_parameters2”之间。

Something like:

喜欢的东西:

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

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

当然,这在很大程度上取决于交换机的语法,但这对我和我的团队都适用。

#7


0  

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

要做到这一点,当使用.proj文件时,您的路径包含在$(DeployFolder)和$(NuGetExe)等属性中时,您可以像这样使用" ';"

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

#1


20  

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!

神奇的效果!

#2


5  

Try add &quot; ex:

尝试添加“;例:

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

#3


4  

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

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

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

#4


1  

> "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.

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

#5


1  

For me the working solution is:

对我来说,有效的解决方案是:

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

/ p:SQLCMD = " \ " C:\ Program Files \ Microsoft SQL Server \ 100 \ \ Binn \ SQLCMD.EXE \工具”“

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

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

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

该属性的MSBuild内的值是:“C:\程序文件\Microsoft SQL Server\100\Tools\Binn\SQLCMD。”EXE”(引号)。

#6


1  

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 ".

如果你在一个开关中有多个参数,你不能通过修正路径来“避免”这个问题。您可以做的是将开关的参数放在“some_parameters1 some_parameters2”之间。

Something like:

喜欢的东西:

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

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

当然,这在很大程度上取决于交换机的语法,但这对我和我的团队都适用。

#7


0  

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

要做到这一点,当使用.proj文件时,您的路径包含在$(DeployFolder)和$(NuGetExe)等属性中时,您可以像这样使用" ';"

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