后生成事件执行的PowerShell [英] Post build event execute powershell

查看:278
本文介绍了后生成事件执行的PowerShell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能建立一个后生成事件执行PowerShell脚本一个.NET项目?我使用这个脚本生成一些文件。也可以我通过它是否是一个调试或发布版本脚本。这方面的一个例子将是巨大的。

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. Also can I pass whether it's a debug or release build to script. An example of this would be great.

推荐答案

下面是一个例子:

的首先:你必须知道的事实,PowerShell的必须配置为执行脚本。下面一行允许PowerShell来执行脚本:

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位系统的devenv.exe的的'在Visual Studio 2010中的可执行文件是一个32位的EXE,所以你需要允许PowerShell的32来执行脚本。

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.

在这里,你可以去你的项目属性和配置后生成如下所示下(法语不好意思):

Once here you can go in your project properties and configure post build as shown here under (sorry in french) :

例如:

下面是文件 psbuild.ps1 ',它创建了一个的test.txt '目标里面配置名称路径。我把意见不同的方式来调试脚本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

这篇关于后生成事件执行的PowerShell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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