构建后事件执行 PowerShell

Post build event execute PowerShell(构建后事件执行 PowerShell)
本文介绍了构建后事件执行 PowerShell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用构建后事件设置 .NET 项目来执行 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.

我还可以将它是调试版本还是发布版本传递给脚本.一个很好的例子.

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 可执行文件是一个 32Bits 的 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)