Reputation: 4804
I have a solution in which I needed to brand an assembly for a third-party client. This resulted in a class structure as follows:
Project1
References
MyBrandedAssembly.dll (namespace: MyAssembly)
Project2
References
Project1
When MsBuild built Project1
, it could resolve the MyAssembly
namespace to MyBrandedAssembly.dll
:
Primary reference "MyAssembly".
Resolved file path is "SolutionPath\Binaries\MyBrandedAssembly.dll".
Reference found at search path location "{HintPathFromItem}".
But when building Project2
, it could not resolve the second-order reference:
Dependency "MyAssembly".
Could not resolve this reference. Could not locate the assembly "MyAssembly".
Check to make sure the assembly exists on disk. If this reference is required by your
code, you may get compilation errors.
For SearchPath "SolutionPath\Project1\bin\Debug".
Considered "SolutionPath\Project1\bin\Debug\MyAssembly", but it didn't exist.
Why not? And how can I force it to?
Upvotes: 2
Views: 118
Reputation: 2487
You can add a pre-build event to your project csproj file to copy the dlls from the Project 1 output bin folder to the Project 2 bin folder. This will allow the assembly to be found by the assembly resolver.
Add this to your project2.csproj
<Target Name="BeforeBuild">
<Delete Files="$(ProjectDir)bin\$(Configuration)\MyBrandedAssembly.dll" />
<Copy SourceFiles="$(ProjectDir)..\<Project1>\bin\$(Configuration)\MyBrandedAssembly.dll" DestinationFolder="$(ProjectDir)bin\$(Configuration)\" />
</Target>
Upvotes: 1