VS Post Build Event

家住魔仙堡 提交于 2019-12-05 19:08:55

问题


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

How is this done?


回答1:


Does that do you want?

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

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




回答2:


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

<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 &&




回答3:


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.




回答4:


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

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

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

Note that, $(Configuration) will be your output folder (e.g. Debug or 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!

P.S. I use Visual Studio 2010




回答5:


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

CodeProject Link & MSDN Ref




回答6:


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

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

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

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




回答7:


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.

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

Hope that helps someone, too!



来源:https://stackoverflow.com/questions/371302/vs-post-build-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!