我刚刚在PowerShell v1.0上测试了这个.设置如下:
Id CommandLine
-- -----------
1 $msbuild = "C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe"
4 $a = "C:\some\project\or\other\src\Solution.sln /target:Clean /target:Build"
Run Code Online (Sandbox Code Playgroud)
.
此行失败,并显示不直观的错误消息:
Id CommandLine
-- -----------
5 & $msbuild $a
Run Code Online (Sandbox Code Playgroud)
.
此行失败,因为&期望第一个参数是命令本身.
Id CommandLine
-- -----------
10 & "$msbuild $a"
Run Code Online (Sandbox Code Playgroud)
.
这条线有效:
Id CommandLine
-- -----------
16 cmd /c "$msbuild $a"
Run Code Online (Sandbox Code Playgroud)
.
请解释.我更感兴趣的是&语法不起作用,而不是MSBuild特定的解决方法.
如何从PowerShell写入stderr,或者捕获这样的错误
这些年来,我throw
通过错误或写作经历幸存下来Write-Error
,但我已经厌倦了,而且在我的脚本中我只想看到一条简洁的错误信息.我一直在努力的每个组合trap
,throw
,Write-Error
,和-ErrorAction
,但无济于事:
try {
throw "error" # Sample code for a stack overflow. In the theater
# of your mind, imagine there is code here that does something real and useful
} catch {
Write-Error "An error occurred attempting to 'do something.' Have you tried rebooting?"
}
Run Code Online (Sandbox Code Playgroud)
这是我想看到的用户体验:
C:\> & .\Do-Something.ps1
An error occurred attempting to 'do something.' Have you tried rebooting?
C:\> ?
Run Code Online (Sandbox Code Playgroud)
相反,我得到:
C:\> …
Run Code Online (Sandbox Code Playgroud) 有人可以向我解释这个结果吗?多年来我试图掌握PowerShell调用命令的语法浪费了很多时间,但是这......我甚至无法猜测如何从输入中获得这个结果.
PS C:\Users\P> & echoargs " ""1"" 2 3 ""4 5 6"" 7 8 9"
Arg 0 is < 1 2 3 4>
Arg 1 is <5>
Arg 2 is <6 7 8 9>
Run Code Online (Sandbox Code Playgroud)
Bueller?
有没有办法捆绑PowerShell,以便我不必在操作系统上安装它?理想情况下,我想在我的构建过程中使用它,但我想要一些独立的东西; 我不想依赖每台安装PowerShell的客户端计算机.我想我会构建一个托管PowerShell环境的控制台应用程序,但是在本地捆绑PowerShell程序集.
假设有可能,这样的设置是否有任何版税/许可问题?
在调试我的WPF项目的过程中,我经常遇到抛出的异常.当这些异常触发时,如果我的应用程序代码抛出了异常,我就可以浏览源代码了.一切都很好.
但是,如果托管在另一个程序集(我们构建的)中的代码抛出异常,我将无法浏览源代码.我曾经在某个时刻提示浏览原始源代码文件,但"取消"了对话框.现在,我想要一个重做.
有没有办法让我重新找到这些源文件?我不再被提示了.我假设Visual Studio在某处存储了我的源代码浏览首选项,但我不知道在哪里.我认为这可能是可以做到的,但我甚至不知道要在Google上搜索以获得我想要的内容.
我该怎么办?
c# debugging visual-studio-2008-sp1 visual-studio-2008 visual-studio
SharePoint计时器作业运行的用户上下文是什么?农场账号?
我将通过计时器作业访问一些外部资源(网络共享),因此我需要知道要授予哪些SharePoint服务帐户权限.
所有,
我正在开发一个SharePoint项目,但这不是特定于SharePoint的问题本身.我有一个已部署到SharePoint服务器场的程序集,我想验证我的"最新版本"是否位于GAC中,或者是否是昨天晚些时候的旧版本代替.这是一个测试农场,所以是的,我们不断地加速版本.
没有做任何疯狂的事情,比如每次编译*时更改程序集版本本身,是否有一些我可以检查(或在编译时设置)的程序集属性?
*我应该澄清一下,在SharePoint项目中,我们在多个位置(包括XML文件)对程序集的全名进行硬编码,因此更改程序集版本的选项不如您想象的那么简单.
是否有直接链接下载Windows PowerShell v2(2.0)RTM?
谷歌搜索结果的第一页没有帮助,我不想下载整个Windows Management Framework.