解决另一个项目重命名的程序集依赖项

时间:2016-02-29 19:02:43

标签: msbuild

我有一个解决方案,我需要为第三方客户端标记一个程序集。这导致了如下的类结构:

Project1
  References
    MyBrandedAssembly.dll (namespace: MyAssembly)
Project2
  References
    Project1

当MsBuild构建Project1时,它可以将MyAssembly命名空间解析为MyBrandedAssembly.dll

Primary reference "MyAssembly".
  Resolved file path is "SolutionPath\Binaries\MyBrandedAssembly.dll".
  Reference found at search path location "{HintPathFromItem}".

但是在构建Project2时,它无法解析二阶引用:

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.

为什么不呢?我怎么能强迫它呢?

1 个答案:

答案 0 :(得分:1)

您可以将预构建事件添加到项目csproj文件,以将dll从Project 1输出bin文件夹复制到Project 2 bin文件夹。这将允许装配解析器找到装配。

将其添加到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>