Skip to content
September 18, 2008 / kiranpatils

After building copy Assembly at some specific folder

Problem:

You have created one Class Library project e.g “BusinessLogic” and other projects are also using it and they are referencing it from C:\MyLibraries folder. Where you put this “Business Logic” Class library. But what happens that you do some changes in your library and forgot to copy it at c:\MyLibraries location. And people starting shout on you…If you are using Visual studio than this thing you can automate using a feature called “Post Build Event”.

Solution

Sounds good idea na….so lets see how can you achieve this step by step:

  1. Right click on your class library and click on properties
  2. It will open up window in left side with list of tabs
  3. Click on “Build Events” Tab.
  4. Here you can see two things:
    1. PreBuild event: comes in action before build.
    2. Postbuild event: comes in action after build.
  5. you can use this DOS Command for achieving the task

COPY Source destination

Click on edit post build event button which will open a window. Here you can see

List of Macros like

TargetDir = your current Class library Bin/debug directory

TargetFileName = your Class library .dll name

And so on which you can explore on your self.

So for copying my .dll to C:\MyLibraries folder I have written like this:

Copy $(TargetDir)\$(TargetFileName) $(TargetDir)\..\..\..\..\ MyLibraries

..\..\..\ = this syntax is for coming up level from child directories. So based on your depth level you can use it wisely.

One Comment

Leave a Comment
  1. fred / Dec 24 2011 12:23 am

    A cleaner approach is:

    “C:\Program Files\Microsoft\ILMerge\ilmerge” /target:winexe /allowDup /wildcards /out:”$(TargetDir)temp.exe” “$(TargetDir)$(TargetFileName)” “$(TargetDir)*.dll”
    COPY “$(TargetDir)temp.exe” “$(TargetDir)$(TargetFileName)”
    COPY “$(TargetDir)$(TargetFileName)” “$(SolutionDir)$(SolutionName)\obj\$(Configuration)\$(TargetFileName)”

Leave a comment