visual-studio VS 构建后事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/371302/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 10:00:14  来源:igfitidea点击:

VS Post Build Event

visual-studiobuildpost-build-event

提问by Michael L

I would like to implement a post build event that performs the following actions

我想实现一个执行以下操作的构建后事件

  1. A relative path copy of the DLL output (1 file, not all the debug jazz)
  2. A register the output DLL to GAC
  1. DLL 输出的相对路径副本(1 个文件,不是所有的调试爵士乐)
  2. A 将输出 DLL 注册到 GAC

How is this done?

这是怎么做的?

回答by Dirk Vollmar

Does that do you want?

那是你想要的吗?

copy $(TargetPath) $(TargetDir)..\..\someFolder\myoutput.dll
regasm $(TargetPath) 

(Entered into the field for post-build step under project properties)

(在项目属性下的后期构建步骤字段中输入)

回答by aku

Enter following into "Project properties->Build events->Post build events command line:"

在“项目属性->构建事件->发布构建事件命令行”中输入以下内容:

xcopy "$(TargetPath)" "target path" /Y && regasm "$(TargetPath)"

or add following snippet to project (e.g. csproj) file

或将以下代码段添加到项目(例如 csproj)文件中

<PropertyGroup>
    <PostBuildEvent>xcopy "$(TargetPath)" "target path" /Y && regasm "$(TargetPath)"</PostBuildEvent>
</PropertyGroup>

Note that it is recommended to add "" around copy command arguments to avoid problems with paths containing whitespaces. Also note that multiple commands can be combined using &&

请注意,建议在复制命令参数周围添加 "" 以避免包含空格的路径出现问题。另请注意,可以使用 && 组合多个命令

回答by Neil Barnwell

Are you sure you want to do this as part of a compile? I would recommend using project references in solutions rather than the GAC if you can avoid it. Copying files is one thing, but registering in the GAC is fairly intrusive and you may want to consider the other environments your code is compiled in. Things like other developers' machines, and test environments/build servers etc. If you have a build server really you should be using something like NAnt with some sort of continuous integration server.

您确定要将其作为编译的一部分吗?如果可以避免的话,我建议在解决方案中使用项目引用而不是 GAC。复制文件是一回事,但在 GAC 中注册相当麻烦,您可能需要考虑编译代码的其他环境。其他开发人员的机器、测试环境/构建服务器等。如果您有构建服务器实际上,您应该将 NAnt 之类的东西与某种持续集成服务器一起使用。

回答by ForceMagic

I had to same issue and I struggled a bit to make it works.

我遇到了同样的问题,我努力让它起作用。

In my case, I wanted to do the other way aroundwhich is copying the SDL dll into my output folder.

就我而言,我想做另一种方式,即将 SDL dll 复制到我的输出文件夹中。

copy "$(SolutionDir)SDL\lib\x86\SDL.dll" "$(SolutionDir)$(Configuration)\"

Note that, $(Configuration)will be your output folder (e.g. Debug or Release).

请注意,$(Configuration)将是您的输出文件夹(例如 Debug 或 Release)。

The quotes was what I was missing, apparently you need them when the right hand side end with a \. Thus, it might be safer to always use them.

引号是我所缺少的,显然当右侧以\. 因此,始终使用它们可能更安全。

Hope to save someone else a 5 minutes!

希望能帮别人节省5分钟!

P.S. I use Visual Studio 2010

PS我使用Visual Studio 2010

回答by Valentino Vranken

For step 2 in the question I seem to prefer the following:

对于问题中的第 2 步,我似乎更喜欢以下内容:

"C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\gacutil" /f /i $(TargetPath)

Note: this requires the Windows SDKto be installed on your development machine.

注意:这需要在您的开发机器上安装Windows SDK

More info on the available macros, such as $(TargetPath), on MSDN.

MSDN 上有关可用宏的更多信息,例如 $(TargetPath)。

回答by Valentino Vranken

you may want to look at MS Build. Its what we use here at work.

你可能想看看 MS Build。它是我们在工作中使用的。

CodeProject Link& MSDN Ref

CodeProject 链接MSDN 参考

回答by John Spiegel

Ran into a related issue. The answers here helped (thanks!).

遇到了一个相关的问题。这里的答案有所帮助(谢谢!)。

My scenario was in debugging an MEF-reliant application I needed to have the related DLLs in a particular location. I ran into issue with overwriting the prior build so did need to add a delete to the script.

我的场景是在调试依赖 MEF 的应用程序时,我需要在特定位置拥有相关的 DLL。我遇到了覆盖先前构建的问题,因此确实需要向脚本添加删除。

delete $(SolutionDir)FileService$(ProjectName).dll
copy $(TargetPath) $(SolutionDir)FileService$(ProjectName).dll

Hope that helps someone, too!

希望也能帮助别人!