- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用Powershell和Psake为Visual Studio解决方案创建打包和部署。
尝试使用msbuild部署数据库项目-使用msdos visual studio命令行可以正常工作
msbuild /target:Deploy /p:UseSandboxSettings=false /p:TargetConnectionString="aConnectionWithSpacesAndSemiColons" "aDatabaseProjectPathWithSpaces"
& msbuild /target:Deploy /p:UseSandboxSettings=false /p:TargetConnectionString="aConnectionWithSpacesAndSemiColons" "aDatabaseProjectPathWithSpaces"
最佳答案
简洁版本
如何将包含引号的参数传递给PowerShell的本机命令?
"/p:Target='Data Source=(local)\SQL;Integrated Security=True'"
→/p:Target='Data Source=(local)\SQL;Integrated Security=True'
'/p:Target=\"Data Source=(local)\SQL;Integrated Security=True\"'
→/p:Target="Data Source=(local)\SQL;Integrated Security=True"
'/p:Target=Data Source=(local)\SQL;Integrated Security=True'
→/p:Target=Data Source=(local)\SQL;Integrated Security=True
/p:Target=`"Data Source=`(local`)\SQL`;Integrated Security=True`"
或/p:Target=Data` Source=`(local`)\SQL`;Integrated` Security=True
→/p:Target=Data Source=(local)\SQL;Integrated Security=True
PS> [string[]]$arguments = @(
'/target:Deploy',
'/p:UseSandboxSettings=False',
'/p:TargetDatabase=UpdatedTargetDatabase',
'/p:TargetConnectionString=\"Data Source=(local)\SQL;Integrate Security=True\"',
'C:\program files\MyProjectName.dbproj'
)
PS> ./echoargs $arguments
Arg 0 is </target:Deploy>Arg 1 is </p:UseSandboxSettings=False>Arg 2 is </p:TargetDatabase=UpdatedTargetDatabase>Arg 3 is </p:TargetConnectionString="Data Source=(local)\SQL;Integrate Security=True">Arg 4 is <C:\program files\MyProjectName.dbproj>
Calling native commands is something that crops up quite a bit as folks move between the legacy cmd system and PowerShell (almost as much as the "separating parameters with commas" gotcha ;).
I've tried and sum up everything I know on the subject of command invocation in PowerShell (v2 and v3) here, along with all the examples and references I can muster.
1.1) At its simplest, for an executable located in the environment path, the command can be called directly, just as you would call a PowerShell cmdlet.
PS> Get-ItemProperty echoargs.exe -Name IsReadOnly
...
IsReadOnly : True
PS> attrib echoargs.exe
A R C:\Users\Emperor XLII\EchoArgs.exe
PS> echoargs arg
The term 'echoargs' is not recognized as the name of a cmdlet, function, script file,
or operable program...
PS> ./echoargs arg
Arg 0 is <arg>
PS> C:\Windows\system32\attrib.exe echoargs.exe
A R C:\Users\Emperor XLII\EchoArgs.exe
PS> $env:Path
...;C:\tools\;...
PS> Copy-Item EchoArgs.exe C:\tools\5pecialCharacter.exe
PS> 5pecialCharacter.exe special character
Bad numeric constant: 5.
PS> & 5pecialCharacter.exe special character
Arg 0 is <special>
Arg 1 is <character>
PS> `5pecialCharacter.exe escaped` character
Arg 0 is <escaped character>
PS> C:\Users\Emperor XLII\EchoArgs.exe path with spaces
The term 'C:\Users\Emperor' is not recognized as the name of a cmdlet, function,
script file, or operable program...
PS> & 'C:\Users\Emperor XLII\EchoArgs.exe' path with spaces
Arg 0 is <path>
Arg 1 is <with>
Arg 2 is <spaces>
PS> C:\Users\Emperor` XLII\EchoArgs.exe escaped` path with` spaces
Arg 0 is <escaped path>
Arg 1 is <with spaces>
PS> $command = 'C:\Users\Emperor XLII\EchoArgs.exe'
PS> $command arg
Unexpected token 'arg' in expression or statement.
PS> & $command arg
Arg 0 is <arg>
PS> $singleArg = 'single arg'
PS> $mushedCommand = "$command $singleArg"
PS> $mushedCommand
C:\Users\Emperor XLII\EchoArgs.exe single arg
PS> & $mushedCommand
The term 'C:\Users\Emperor XLII\EchoArgs.exe single arg' is not recognized as the
name of a cmdlet, function, script file, or operable program...
PS> & $command $singleArg
Arg 0 is <single arg>
PS> $multipleArgs = 'multiple','args'
PS> & $command $multipleArgs
Arg 0 is <multiple>
Arg 1 is <args>
$args
是PowerShell中的一个自动变量,它可能导致保存在其中的值被覆盖;相反,最好使用诸如
$msbuildArgs
之类的描述性名称,以避免命名冲突。)
PS> $mungedArguments = 'initial argument'
PS> $mungedArguments += 'second argument'
PS> $mungedArguments += $(if( $someVariable ) { 'dynamic A' } else { 'dynamic B' })
PS> ./echoargs $mungedArguments
Arg 0 is <initial argumentsecond argumentdynamic B>
PS> $arrayArguments = @('initial argument')
PS> $arrayArguments += 'second argument'
PS> $arrayArguments += $(if( $someVariable ) { 'dynamic A' } else { 'dynamic B' })
PS> ./echoargs $arrayArguments
Arg 0 is <initial argument>
Arg 1 is <second argument>
Arg 2 is <dynamic B>
PS> $cmdletArgs = @{ Path = 'EchoArgs.exe'; Name = 'IsReadOnly' }
PS> $cmdlet = 'Get-ItemProperty'
PS> & $cmdlet $cmdletArgs # hashtable object passed to cmdlet
Cannot find path 'C:\Users\Emperor XLII\System.Collections.Hashtable'...
PS> & $cmdlet @cmdletArgs # hashtable values passed to cmdlet
...
IsReadOnly : True
PS> ./echoargs @cmdletArgs
Arg 0 is <Name>
Arg 1 is <IsReadOnly>
Arg 2 is <Path>
Arg 3 is <EchoArgs.exe>
`
或通过将参数放在单引号字符串内来完成。
PS> ./echoargs money=$10.00
Arg 0 is <money=.00>
PS> ./echoargs money=`$10.00
Arg 0 is <money=$10.00>
PS> ./echoargs value=(spaces and parenthesis)
The term 'spaces' is not recognized as the name of a cmdlet, function, script file,
or operable program...
PS> ./echoargs 'value=(spaces and parenthesis)'
Arg 0 is <value=(spaces and parenthesis)>
PS> ./echoargs value="double quotes"
Arg 0 is <value=double quotes>
PS> ./echoargs 'value="string double quotes"'
Arg 0 is <value=string>
Arg 1 is <double>
Arg 2 is <quotes>
PS> ./echoargs value=`"escaped double quotes`"
Arg 0 is <value=escaped double quotes>
PS> ./echoargs 'value=\"backslash escaped double quotes\"'
Arg 0 is <value="backslash escaped double quotes">
PS> ./echoargs value='single quotes'
Arg 0 is <value=single quotes>
PS> ./echoargs "value='string single quotes'"
Arg 0 is <value='string single quotes'>
PS> ./echoargs value=`'escaped` single` quotes`'
Arg 0 is <value='escaped single quotes'>
--%
(请参阅
about_Parsing
)。当在复杂参数之前使用时,
--%
将按原样传递参数,而不进行任何解析或变量扩展,除了类似cmd的%ENVIRONMENT_VARIABLE%
值之外。
PS> ./echoargs User:"$env:UserName" "Hash"#555
Arg 0 is <User:Emperor XLII>
Arg 1 is <Hash>
PS> ./echoargs User: "$env:UserName" --% "Hash"#555
Arg 0 is <User:Emperor XLII>
Arg 1 is <Hash#555>
PS> ./echoargs --% User: "%USERNAME%" "Hash"#555
Arg 0 is <User:Emperor XLII>
Arg 1 is <Hash#555>
PS> $user = 'User:"%USERNAME%"'
PS> $hash = 'Hash#' + $hashNumber
PS> $mungedArguments = $user,$hash -join ' '
PS> ./echoargs $mungedArguments
Arg 0 is <User:%USERNAME% Hash#555>
PS> ./echoargs --% $mungedArguments
Arg 0 is <$mungedArguments>
PS> ./echoargs '--%' $mungedArguments
Arg 0 is <User:Emperor XLII>
Arg 1 is <Hash#555>
EchoArgs.exe
,它是
PowerShell Community Extensions的控制台应用程序,它简单地写回在尖括号之间传递给它的参数(如上面的示例所示)。
Trace-Command
,它是一个cmdlet,可以显示PowerShell如何处理管道的许多详细信息。特别是,
NativeCommandParameterBinder
跟踪源将显示PowerShell接收并传递给本机命令的内容。
PS> Trace-Command *NativeCommand* { ./echoargs value="double quotes" } -PSHost
DEBUG: NativeCommandParameterBinder : Raw argument string: "value=double quotes"
DEBUG: NativeCommandParameterBinder : Argument 0: value=double quotes
PS> Trace-Command *NativeCommand* { ./echoargs 'value="double quotes"' } -PSHost
DEBUG: NativeCommandParameterBinder : Raw argument string: "value="double quotes""
DEBUG: NativeCommandParameterBinder : Argument 0: value=double
DEBUG: NativeCommandParameterBinder : Argument 1: quotes
PS> Trace-Command *NativeCommand* { ./echoargs value=`"double quotes`" } -PSHost
DEBUG: NativeCommandParameterBinder : Raw argument string: value="double quotes"
DEBUG: NativeCommandParameterBinder : Argument 0: value=double quotes
PS> Trace-Command *NativeCommand* { ./echoargs 'value=\"double quotes\"' } -PSHost
DEBUG: NativeCommandParameterBinder : Raw argument string: "value=\"double quotes\""
DEBUG: NativeCommandParameterBinder : Argument 0: value="double quotes"
关于powershell - Powershell调用带嵌套引号的msbuild,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6224638/
我有一个类似 ( www.bbcurdu.com) 的网站。现在我的问题是,当我添加一个带有引号或引号的新故事时,它不会保存在数据库中。如果我删除这些逗号或引号,那么它将保存在数据库中。并正确获取和显
我正在使用(并坚持使用)以下版本的 Ruby: ruby 1.8.7 (2012-06-29 patchlevel 370) [x86_64-linux] 我尝试了很多谷歌搜索,但找不到解决我的问题的
我有以下示例数据, 我想连接 string1 和 string2 以产生连接结果 "a""b" 使用连接函数 我在官方的microsoft excel文档中没有找到任何答案 https://suppo
我是 SQL-mySQL 方面的 super 新手,我想查询这些包含具有特定值的列的条目,但该值中已经有引号,它实际上看起来像这样,引号已经存在:“荷兰鹿特丹 Voor Land-en Volkenk
是否有一个简单的正则表达式来匹配所有 unicode 引号?还是必须像这样手动编码: quotes = ur"[\"'\u2018\u2019\u201c\u201d]" 感谢阅读。 布莱恩 最佳答案
我有下面的代码,禁止将特殊字符插入到 HTML 表单上提交的文本中。 可以看出,我需要禁用的特殊字符位于引号之间,而我需要禁用引号 " 本身,但我不能这样做,因为如果我添加另一个中间的引号然后读起来就
对于给定的输入字符串 abc,[def,ghi,ijk],lm,(no,pq,rs),[tu,vw,xy],zs,"as,as,fr"输出应该是 abc [def,ghi,ijk] lm (no,pq
下午好,快乐 4 我在处理一些 javascript 时遇到了问题....我是一个初学者,正在使用这个特定的在线示例来了解如何淡入和淡出多个引号... 我已经实现了 HTML/Javascript/C
我想在一段文本周围加上引号。文本不能超过 3 行:如果超过,我想要一个省略号(并且我仍然想要引号)。我附上我现在拥有的东西。我的解决方案使用 JS:虽然纯 CSS 解决方案是理想的,但可能的 CSS
我将它发送给一个函数,我想在下面的变量值周围加上双引号,例如 $var = "New York"(注意引号) $fq.=" + area:$state"; 所以当我回显 $state 时我想用双
这个问题在这里已经有了答案: How can I make Java print quotes, like "Hello"? (11 个答案) 关闭 9 年前。 我想在 java 中打印反引号。但是
我认为这是 F# 的一个众所周知的限制,但我找不到任何好的解决方法…… 所以,这里是代码(我试图让它尽可能简单,所以它可能看起来没有任何意义): [] type Human (makeAName: u
我在Windows 7上,在Apache 2.4上使用PHP 5.6.14版:我必须使用PHP在SQLite3数据库上构建查询选择。 NOTA:我是PHP的再见..... 我的代码如下 '; echo
在 jQuery 文档中,大多数字符串都是使用单引号“声明”的。包括documentation用于 jQuery UI。 那为什么不呢 $(".datepicker").datepicker({ da
我正在尝试在 Java 中使用以下正则表达式,它应该与任何 lang="2-char-lang-name" 匹配: String lang = "lang=\"" + L.detectLang(inp
我试图在 more 之后插入一个 block 引用指令,不接受任何参数: First paragraph. .. more:: Blockquote here! -- Author S
我从外部进程获得了一些我无法更改的 JSON,并且我需要修改此 JSON 字符串才能使下游 Java 进程正常工作。 JSON 字符串如下所示: {"widgets":"blah","is_dog":
我试图在从数据库读取数据后生成 CSV 文件。现在单个数据可以包含逗号、单引号和双引号。 请告诉我如何在正则表达式的帮助下处理这种情况。 最佳答案 您可以为 CSV 文件使用不同的分隔符吗?也许是一个
我尝试在 codemodel(Sun) 中创建下一个表达式: driver.findElement(By.xpath("//div[text()=\""+whatToclick+"\"]/pare
我需要知道报价和列表之间的区别。例如: cl-prompt> (equal (first (list * 1 2)) *) T cl-prompt> (equal (first '(* 1 2)) *
我是一名优秀的程序员,十分优秀!