生成后事件执行 PowerShell

编程入门 行业动态 更新时间:2024-10-27 02:23:07
本文介绍了生成后事件执行 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",其中包含配置名称.我在评论中添加了不同的方式来调试您的后期构建脚本(消息框、声音、输出消息)

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

本文发布于:2023-11-13 10:13:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584108.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:事件   PowerShell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!