C #: Elegant way to copy native dependencies next to my exe

I am currently using the post-build event command line like this:

xcopy /Y /R d:\svn\some\directory\somedll.dll  $(TargetDir)

      

The problem is this: when others check the code against a different directory, they will have to fix the path in that command. Is there a less hacky way to do this?

+2


source to share


3 answers


Assuming it d:\svn\some\directory

's in a fixed location relative to your file .sln

, you can use a relative path like this:

xcopy /Y /R $(SolutionDir)..\directory\somedll.dll $(TargetDir)

      



(Note that the value $(SolutionDir)

includes a trailing backslash.)

+6


source


If d:\svn\some\directory

located in your solution folder, you can add somedll.dll

Visual Studio to the solution and set Copy to Output Directory to Copy Always in the file properties.



+5


source


Instead of using the command line in a post-build event, you can use the actual msbuild tasks as part of the build script by editing the .csproj

.

Here is RichieHindle 's answer using the msbuild task rather than xcopy:

<Target Name="PostBuild">
    <Copy
        SourceFiles="$(SolutionDir)..\directory\somedll.dll"
        DestinationFolder="$(TargetDir)"
        />
</Target>

      

In the file, .csproj

you should see a missing stub for pre / post build targets.

+2


source







All Articles