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

Msbuild 解决另一个项目';已重命名的程序集依赖项,msbuild,Msbuild,我有一个解决方案,其中我需要为第三方客户的装配打上品牌。这产生了如下的类结构: Project1 References MyBrandedAssembly.dll (namespace: MyAssembly) Project2 References Project1 当MsBuild生成Project1时,它可以将MyAssembly命名空间解析为MyBrandedAssembly.dll: Primary reference "MyAssembly". Reso

我有一个解决方案,其中我需要为第三方客户的装配打上品牌。这产生了如下的类结构:

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.

为什么不呢?如何强制执行?

您可以将预生成事件添加到项目csproj文件中,以将DLL从项目1输出bin文件夹复制到项目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>


你能在Project2中添加对MyBrandedAssembly.dll的引用吗?我可以,但有没有更“自动”的方法?这个线程有一个替代解决方案可以为你工作:@SteveWong:你在考虑顶级解决方案吗?既需要参考又需要代码;更不自动的是,我理解了公认的答案,您有2个选项:1)添加对依赖程序集的引用(在Project2中)或2)从Project1代码中引用依赖程序集的类型。此外,如果您有需要复制的DLL列表,您可以创建一个项目组并在源文件中引用该项目组。查看其他参数和使用文件列表的示例