AspBucket offers ASP.NET, C#, VB, Jquery, CSS, Ajax, SQL tutorials. It is the best place for programmers to learn

Tuesday, 20 June 2017

How to copy the item to specific location in the output directory in MSBuild Project?

In a Project we need to load the external libraries that are located inside an ExternalDLLs folder On the build of the application each dll should place inside an execution directory. But on build of application it creates an folder inside the debug with name ExternalDLLs then it place dll inside of it.

Directory Structure
Each dll property "Copy to output directory" is set as "Copy if newer"





Current .csproj file contains following code

 <ItemGroup>
    <Content Include="ExternalDLLs\example1.dll" >  
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
 </Content>
    <Content Include="ExternalDLLs\example2.dll">    
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
 </Content>
  </ItemGroup>

Following is the directory structure for output directory as you can see it also create the directory inside the output directory.


If you don't want to include the folder inside the output directory copy the dll directly to output directory then add the link tag with value
%(Filename)%(Extension)
 <ItemGroup>
    <Content Include="ExternalDLLs\example1.dll" >
  <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
 </Content>
    <Content Include="ExternalDLLs\example2.dll">
     <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
 </Content>
  </ItemGroup>

It will fix the problem and dll under the ExternalDLLs will directly put inside the output directory.


0 comments :

Post a comment

  • Popular Posts
  • Comments