[英]Pre-build action
As part of a build process, I need to replace some of the code in ac# project at pre-build time.作为构建过程的一部分,我需要在预构建时替换 ac# 项目中的一些代码。 I hoped there is some hook available to specify in
.csproj
file.我希望有一些钩子可以在
.csproj
文件中指定。 I am using Rider.我正在使用骑士。 This article appears to be about what I need;
这篇文章似乎是关于我所需要的; https://docs.microsoft.com/en-us/visualstudio/ide/reference/pre-build-event-post-build-event-command-line-dialog-box?view=vs-2019 , but I am not sure how to use it in
.csproj
. https://docs.microsoft.com/en-us/visualstudio/ide/reference/pre-build-event-post-build-event-command-line-dialog-box?view=vs-2019 ,但我不是确定如何在
.csproj
使用它。
How do you specify pre-build actions in c#?你如何在 C# 中指定预构建操作?
You could define a BeforeBuild target in your csproj to run a command.您可以在 csproj 中定义一个 BeforeBuild 目标来运行命令。 Say, for example, I had a PS script I wanted to run:
比如说,我有一个想要运行的 PS 脚本:
<Target Name="BeforeBuild">
<Exec Command="$(PowerShellExe) -NonInteractive -executionpolicy Unrestricted
-command "& invoke-command -scriptblock {
&'$(ScriptLocation)'
'$(LogFileLocation)'
'$(MSDeployComputerName)'}
""/>
</Target>
Inside the .csproj
you can add this:在
.csproj
您可以添加以下内容:
<PropertyGroup>
<PreBuildEvent>start %25comspec%25</PreBuildEvent>
</PropertyGroup>
This only starts a cmd Window in that case but you can replace it.在这种情况下,这只会启动一个 cmd 窗口,但您可以替换它。 Also you can place it in the property group you want to use.
您也可以将其放在要使用的属性组中。 See docs
查看文档
Also I want to note the preprocessor directives specifically #if .另外我想特别注意预处理器指令#if 。 When you want to replace DEBUG Code, that only should be present in DEBUG Environment and it's a static replacement, this would be easier.
当你想替换调试代码时,它应该只存在于调试环境中,它是一个静态替换,这会更容易。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.