Build Process and Powershell - Visual Studio Project



我正在尝试将脚本(可能是PowerShell脚本)添加到我的Visual Studio C#项目中。此脚本的目标是在每次生成项目时重新创建一个文件。理想情况下,每次我想生成项目时,此脚本都会在 Visual Studio 的生成过程之前运行。

我对这个过程完全陌生,我似乎没有找到一种方法(或理解)一种方法来做到这一点。

提前感谢您的帮助!

编辑:这是我的PowerShell脚本的样子。

$file_path = 'C:Users<username>DesktopTestScripts'
$file_name = 'test.xml'
$file = $file_path +''+ $file_name
$file_exist = Test-Path $file
If($file_exist)
{
    Remove-Item $file
}
$file_header_comment = '<!-- This file was auto generated during the build process -->'
New-Item -Path $file_path -Name $file_name -Value $file_header_comment -ItemType file -force

在项目属性的"生成事件"选项卡上,在"预生成事件"命令行上调用脚本。像这样:

Powershell.exe -File myScript.ps1

最新更新