.NET Framework Bookmark and Share   
 index > MSBuild > How to copy the referenced assemblies of a project to the output directory?
 

How to copy the referenced assemblies of a project to the output directory?

Hi,

My case is this: I have a solution under which 5 projects(4 class libraries and one WPF library). I use Ms Build to build this solution and then copy the build files to the specified output directory. After building; 4 dlls and one exe and the nhibernate mapping files which I included are copied to the output directory. When I run exe; it fails and shows this message :

"Could not load file or assembly 'Xceed.Wpf.DataGrid, Version=2.0.8277.15250, Culture=neutral, PublicKeyToken=ba83ff368b7563c6' or one of its dependencies. The system cannot find the file specified."

And whwn I manually add the dll of Xceed.Wpf.DataGrid; exe "ll run. So how can I include the dlls/assemblies of my projects to the output directory using MS Build.

My MS Build script file is :

<?xml version="1.0" encoding="utf-8"?>

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets ="BuildAll">

<PropertyGroup>
<OutputPath>Deploy\</OutputPath>
<Configuration>Release</Configuration>
</PropertyGroup>

<PropertyGroup>
<BuildAllDependsOn>CleanAll;CoreBuild;CopyFiles</BuildAllDependsOn>
</PropertyGroup>

<ItemGroup>
<ProjectsToBuild Include="**\*proj" Exclude="$(MSBuildProjectFile)"/>
<MappingFiles Include="QSS.Neon.Marketing\*hbm.xml"/>
</ItemGroup>


<Target Name="BuildAll" DependsOnTargets="$(BuildAllDependsOn)">
</Target>

<Target Name="CleanAll">
<CreateItem Include="$(OutputPath)\**\*dll;$(OutputPath)\**\*exe">
<Output ItemName="GeneratedFiles" TaskParameter="Include"/>
</CreateItem>
<Delete Files="@(GeneratedFiles)"></Delete>
<MSBuild Projects="@(ProjectsToBuild)" Targets="Clean" Properties="Configuration=$(Configuration);"/>
</Target>

<Target Name="CoreBuild">
<MSBuild Projects ="@(ProjectsToBuild)" ContinueOnError="false" Properties="Configuration=$(Configuration)">
<Output ItemName ="OutputFiles" TaskParameter="TargetOutputs"/>
</MSBuild>
<!--<Csc References="@(Reference)"/>-->
</Target>

<Target Name="Copyfiles">
<Copy SourceFiles="@(OutputFiles)" DestinationFiles="@(OutputFiles->'$(OutputPath)%(RecursiveDir)%(Filename)%(Extension)')"/>
<Copy SourceFiles="@(MappingFiles)" DestinationFiles="@(MappingFiles->'$(OutputPath)%(RecursiveDir)%(Filename)%(Extension)')"/>
</Target>

</Project>


Asif Abdulla
[Quadra Softwares-India]Asif Abdulla

Hi Asif Abdulla,

In Visual Studio, we can set Copy Local to True to copy the referred dll to the project output directory. When we set the Copy Local to True, Visual Studio will add the <Private>True</Private> to the specified reference. Please try to use the Private tag to copy the assembly to project output directory and then copy it to the destination.

<Reference Include=QSS.Neon.Marketing.UI\bin\Debug\Xceed.Wpf.Controls.dll">

<Private></Private>

</Reference>

Best regards,
Rong-Chun Zhang

Please mark the replies as answers if they help and unmark if they don't.
Rong-Chun Zhang
One more thing to add;

i can add those dlls by

<ItemGroup>
<!-- UI-->
<Reference Include="QSS.Neon.Marketing.UI\bin\Debug\Xceed.Wpf.Controls.dll"/>
<Reference Include="QSS.Neon.Marketing.UI\bin\Debug\Xceed.Wpf.DataGrid.dll"/>
<!-- DAL-->
<Reference Include="QSS.Neon.Marketing.DataAccessLayer\bin\Release\Castle.DynamicProxy2.dll"/>
<Reference Include="QSS.Neon.Marketing.DataAccessLayer\bin\Release\Iesi.Collections.dll"/>
<Reference Include="QSS.Neon.Marketing.DataAccessLayer\bin\Release\log4net.dll"/>
<Reference Include="QSS.Neon.Marketing.DataAccessLayer\bin\Release\NHibernate.dll"/>

</ItemGroup>

and then copying those into my output directory as

<Target Name="Copyfiles">
<Copy SourceFiles="@(OutputFiles)" DestinationFiles="@(OutputFiles->'$(OutputPath)%(RecursiveDir)%(Filename)%(Extension)')"/>
<Copy SourceFiles="@(MappingFiles)" DestinationFiles="@(MappingFiles->'$(OutputPath)%(RecursiveDir)%(Filename)%(Extension)')"/>
<Copy SourceFiles="@(Reference)" DestinationFiles="@(Reference->'$(OutputPath)%(RecursiveDir)%(Filename)%(Extension)')"/>
</Target>

But is there any other way to add the dlls referred by the projects without specifying as above.
Also why the common reference dlls for every project such as System.dll is not seen at the output/bin folder?



Asif Abdulla
[Quadra Softwares-India]Asif Abdulla

Hi Asif Abdulla,

In Visual Studio, we can set Copy Local to True to copy the referred dll to the project output directory. When we set the Copy Local to True, Visual Studio will add the <Private>True</Private> to the specified reference. Please try to use the Private tag to copy the assembly to project output directory and then copy it to the destination.

<Reference Include=QSS.Neon.Marketing.UI\bin\Debug\Xceed.Wpf.Controls.dll">

<Private></Private>

</Reference>

Best regards,
Rong-Chun Zhang

Please mark the replies as answers if they help and unmark if they don't.
Rong-Chun Zhang
Thanks Rong-Chun Zhang for your quick reply; but by default itself the property Copy Local to True is set for those dlls; I checked it. Still then I have to add the references manually from the output directory as you can see it in my MS Build project file. So why it's not copied then?

The hands that help are holier than the lips that pray
[Quadra Softwares-India]Asif Abdulla

HiAsif Abdulla,

As far as I know, the default value forCopy Local of the references is false.And when Copy Local is set to true, the refered assebmly is marked as Private to true. Please try to mark the references to private like I provided in my last reply.

Best regards,
Rong-Chun Zhang
Please mark the replies as answers if they help and unmark if they don't.
Rong-Chun Zhang

Hello Asif Abdulla!

I suppose if you're trying to set the CopyLocal property via VisualStudio and yourassemby in the GAC then you are having no luck.If the referenced assembly in the GAC the VS do not add the 'Private' tag under your 'Reference'. Butyou can add it manually with thetext editor and it would work as described above!

Good luck,
Sergei Vedichev.

sved
Actually the copy local flag is implied depending on if the referenced assembly is strongly named and is in the GAC or not. This caused me no end of issues, you can see my findings in my blog post

http://bronumski.blogspot.com/2009/06/project-reference-fun-and-games.html
Bronumski

You can use google to search for other answers

Custom Search

More Threads

• Nant to MSBuild converter
• MSBuild problem with mixed Bts and C# projects in a solution
• sample build script required
• Really Stupid Newbie Question
• Task dll is locked after build
• Customise 'Deploy' for Smart Device Projects
• Web project build problem
• Can the Get Task fetch more than one folder?
• VS2008, C++, Build Failed, no entries in Error List in VS IDE
• Log.LogMessage & Output Windows