间隔路径、msbuild 和 psake [英] Spaced paths, msbuild, and psake

查看:61
本文介绍了间隔路径、msbuild 和 psake的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

相关问题此处.

这适用于编译 mvc3 应用程序.

This works properly for compiling an mvc3 application.

task Compile 
{
    $config = $script:siteConfig.config

    exec { & "C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe" $webproject_path `
    /p:Configuration=$config /p:WebProjectOutputDir="$publish_dir" `
    /p:Outdir="$out_dir" /p:CleanWebProjectOutputDir=False `
    /T:_WPPCopyWebApplication /T:ResolveReferences /verbosity:quiet /nologo }
}

所有这些路径变量都是脚本属性.但是,当在这些计算路径中引入空格时(例如,项目从 C:\Projects\ 移动到 C:\Users\ASDFG1\Documents\Visual Studio 2010\Projects),msbuild 认为有多个项目文件.这是有道理的,但我必须遗漏一些东西,将解析的变量放入引号中不应该这么难.

All of those path variables are script properties. However, when spaces are introduced in those calculated paths (e.g. the project is moved from C:\Projects\ to C:\Users\ASDFG1\Documents\Visual Studio 2010\Projects) msbuild thinks there's multiple project files. This makes sense but I have to be missing something, getting a parsed variable into quotes shouldn't be this hard.

尝试的变体

exec { Invoke-Expression "& C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe '$webproject_path' /p:Configuration=$config /p:WebProjectOutputDir='$publish_dir' /p:Outdir='$out_dir' /p:CleanWebProjectOutputDir=False /T:_WPPCopyWebApplication /T:ResolveReferences /verbosity:quiet /nologo" }

exec { C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe "`"$webproject_path`"" `
/p:Configuration=$config /p:WebProjectOutputDir="`"$publish_dir`"" `
/p:Outdir="`"$out_dir`"" /p:CleanWebProjectOutputDir=False `
/T:_WPPCopyWebApplication /T:ResolveReferences /verbosity:quiet /nologo }

推荐答案

使用 EchoArgs.exe 重现问题,我们看到引号没有按需要传递给可执行文件:

Using EchoArgs.exe to reproduce the problem, we see that quotes are not being passed to the executable as desired:

PS> $publish_dir = 'C:\Users\Documents\Visual Studio 2010\Projects'
PS> ./echoargs /p:WebProjectOutputDir="$publish_dir"
Arg 0 is </p:WebProjectOutputDir=C:\Users\Documents\Visual Studio 2010\Projects>

PS> ./echoargs /p:WebProjectOutputDir="`"$publish_dir`""
Arg 0 is </p:WebProjectOutputDir=C:\Users\Documents\Visual>
Arg 1 is <Studio>
Arg 2 is <2010\Projects>


使用 this answer 中的反斜杠转义选项,我们可以保留变量扩展和封闭引号:


Using the backslash-escaping option from this answer, we can preserve the variable expansion and the enclosing quotes:

PS> ./echoargs /p:WebProjectOutputDir=\`"$publish_dir\`"
Arg 0 is </p:WebProjectOutputDir="C:\Users\Documents\Visual Studio 2010\Projects">

在这里,反引号告诉 PowerShell 将引号字符视为文字值,反斜杠告诉调用调用保留引号.

Here, the backticks tell PowerShell to treat the quote characters as literal values, and the backslash tells the call invocation to preserve the quotes.


或者,我们可以通过预先评估完整参数来坚持单一级别的转义,而不是内联 $publish_dir 变量:

PS> $publishArg = '/p:WebProjectOutputDir=\"{0}\"' -f $publish_dir
PS> ./echoargs $publishArg
Arg 0 is </p:WebProjectOutputDir="C:\Users\Documents\Visual Studio 2010\Projects">

这篇关于间隔路径、msbuild 和 psake的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆