12

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?

Mihai Limbășan
  • 64,368
  • 4
  • 48
  • 59
Michael L
  • 5,560
  • 7
  • 29
  • 32

8 Answers8

16

Does that do you want?

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

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

Dirk Vollmar
  • 172,527
  • 53
  • 255
  • 316
  • 7
    On Microsoft Visual Studio 2010, this will fail with a 9009 error: you need to use the full path to regasm, as follows: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe $(TargetPath) – Contango Oct 08 '10 at 11:48
8

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

aku
  • 122,288
  • 32
  • 173
  • 203
5

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.

Neil Barnwell
  • 41,080
  • 29
  • 148
  • 220
2

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

ForceMagic
  • 6,230
  • 12
  • 66
  • 88
1

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

CodeProject Link & MSDN Ref

  • Yes, MSBuild is excellent for that. If you want to stay inside Visual Studio you could also enter post-build commands under project properties. – Dirk Vollmar Dec 16 '08 at 13:47
1

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.

Valentino Vranken
  • 5,597
  • 1
  • 26
  • 28
1

This question is old. The easiest way is to add something like this on your .csproj file. For example I am running some tests on a virtual machine and its nice to have it sent to it after I compile:


<Project>
    ...
     <!-- Upload to virtual machine -->
    <Target Name="rsync" AfterTargets="Build">
        <Exec Command="C:\Windows\System32\wsl.exe rsync -azv -e 'ssh -i /path/to/my/private/key' --delete  /mnt/c/repos/MyProject/bin/Debug/net7.0/ root@vm.ublux.com:/usr/share/foo/" />
    </Target>
</Project>

Tono Nam
  • 34,064
  • 78
  • 298
  • 470
0

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!

John Spiegel
  • 1,861
  • 3
  • 24
  • 39