Question

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?

Was it helpful?

Solution

Does that do you want?

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

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

OTHER TIPS

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

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.

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

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

CodeProject Link & MSDN Ref

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.

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top