問題描述
是否可以使用構(gòu)建后事件設(shè)置 .NET 項目來執(zhí)行 powershell 腳本?我正在使用這個腳本來生成一些文件.
Is it possible to set up a .NET project with a post build event to execute a powershell script? I am using this script to generate some files.
我還可以將它是調(diào)試版本還是發(fā)布版本傳遞給腳本.一個很好的例子.
Also can I pass whether it's a debug or release build to script. An example of this would be great.
推薦答案
這里是一個例子:
首先:您必須意識到必須配置 PowerShell 才能執(zhí)行腳本.以下行允許 PowerShell 執(zhí)行腳本:
First of all : you must be aware of the fact that PowerShell must be configure to execute scripts. The following line allow PowerShell to execute scripts :
Set-ExecutionPolicy RemoteSigned
此處特別提及:如果您運行的是 64 位系統(tǒng),則必須注意 'devenv.exe' Visual Studio 2010 可執(zhí)行文件是一個 32Bits 的 exe,所以你需要允許 PowerShell 32 執(zhí)行腳本.
Special mention here : if you are running a 64bits system you've got to take care of the fact that 'devenv.exe' the Visual Studio 2010 executable is a 32Bits exe, so you need to allow PowerShell 32 to execute scripts.
在這里,您可以進入您的項目屬性并配置后期構(gòu)建,如下所示(對不起,法語):
Once here you can go in your project properties and configure post build as shown here under (sorry in french) :
例如:
這里是文件'psbuild.ps1
',它在目標路徑中創(chuàng)建一個'test.txt
',里面有配置名稱.我評論了不同的方式來調(diào)試你的 postbuild 腳本(消息框、聲音、輸出消息)
Here is the file 'psbuild.ps1
', it creates a 'test.txt
' in the target path with the configuration name inside. I put in comment different ways to debug your postbuild script (message box, sound, message on the output)
param ([string]$config, [string]$target)
#[void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
#[void][System.Windows.Forms.MessageBox]::Show("It works.")
#[Console]::Beep(600, 800)
#Write-Host 'coucou'
set-content $target -Value $config -Force
這篇關(guān)于構(gòu)建后事件執(zhí)行 PowerShell的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!