MsBuild不会在自定义任务的第二级依赖项的良好目录中查找

时间:2010-09-09 16:30:03

标签: msbuild dependencies msbuild-task assembly-resolution probing

我写了一个MsBuild任务:MyTask。在我的解决方案中,我有Task项目和其他项目。 MyTask引用了一个引用第三个程序集的项目(比如ProjA),比如说(dep1和dep2)。

项目都构建良好,我将输出放在一个目录(Compil)中。在这个目录中我拥有我想要的所有dll:MyTask.dll,ProjA.dll,dep1.dll,dep2.dll等。

在我的MsBuild文件中,我包含自定义任务程序集:

<UsingTask AssemblyFile="..\Compil\MyTask.dll" TaskName="CreateSitesCss" />

然后我调用MyTask程序集的任务。该调用执行得很好但是MsBuild抱怨没有找到dep1和dep2程序集(尽管它们位于同一目录中):

  

错误:无法加载文件或程序集'dep1,Version = 2.0.0.0,Culture = neutral,PublicKey Token = 9109c11469ae1bc7'或其依赖项之一。系统找不到指定的文件。

我可以通过将dep1.dll和dep2.dll复制到c:\ windows \ microsoft .net \ framework \ v4.0 \来解决此问题,但我不想这样做,因为它在构建其他项目时会触发问题(不会将dep1.dll和dep2.dll复制到输出目录......)。

有没有人有同样的问题或更好的解决方案?


修改

以下是Fusion Log Viewer的输出

*** Assembly Binder Log Entry  (19/10/2010 @ 17:52:45) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = HEADOFFICE\bbaumann
LOG: DisplayName = ProjA
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: ProjA | Domain ID: 1
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///c:/WINDOWS/Microsoft.NET/Framework/v4.0.30319/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MSBuild.exe
Calling assembly : System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
WRN: Not probing location file:///d:/svn/twilight/_build/ProjA.DLL, because the location falls outside of the appbase.
WRN: Not probing location file:///d:/svn/twilight/_build/ProjA/ProjA.DLL, because the location falls outside of the appbase.
WRN: Not probing location file:///d:/svn/twilight/_build/ProjA.EXE, because the location falls outside of the appbase.
WRN: Not probing location file:///d:/svn/twilight/_build/ProjA/ProjA.EXE, because the location falls outside of the appbase.
LOG: Attempting download of new URL file:///c:/WINDOWS/Microsoft.NET/Framework/v4.0.30319/ProjA.DLL.
LOG: Attempting download of new URL file:///c:/WINDOWS/Microsoft.NET/Framework/v4.0.30319/ProjA/ProjA.DLL.
LOG: Attempting download of new URL file:///c:/WINDOWS/Microsoft.NET/Framework/v4.0.30319/ProjA.EXE.
LOG: Attempting download of new URL file:///c:/WINDOWS/Microsoft.NET/Framework/v4.0.30319/ProjA/ProjA.EXE.
LOG: All probing URLs attempted and failed.

如果我将MsBuild.exe复制到我所有dll所在的目录中,它的工作正常...... MsBuild似乎在我的Compil目录中找不到dep1.dll和dep2.dll,即使它在...中找到了ProjA.dll ...


修改

关于我的绑定是如何完成的: MyTask通过以下方式引用ProjA项目:

<ProjectReference Include="..\ProjA\ProjA.csproj">
   <Project>{ED61DCC3-D759-4D44-B802-A6A46F328402}</Project>
   <Name>ProjA</Name>
</ProjectReference>

ProjA通过

引用两个依赖项
<Reference Include="dep1, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\Dependencies\dep1\dep1.dll</HintPath>
</Reference>
<Reference Include="dep2, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\Dependencies\dep2\dep2.dll</HintPath>
</Reference>

2 个答案:

答案 0 :(得分:2)

您可以尝试使用Fusion Log Viewer(fuslogvw.exe,与VisualStudio一起安装)来查看正在搜索程序集的路径。您可能会找到另一个可以使用的文件夹。

如果dep1和dep2是第三方程序集或内部程序集,它们不会更改,您可以随时将它们放入GAC中。这通常是我在构建服务器上避免的,但是如果你只是将它们用于构建帮助程序而不是生产安装,那么它应该不是问题。

编辑:partial bind可能是原因。您使用Assembly.Load使用ProjA吗?从您提供的日志中看,它似乎无法加载ProjA - 即使尝试加载dep1或dep2也远远不够。

答案 1 :(得分:0)

我可以采取一些可以解决的问题。

  1. ILMerge这将允许您将多个程序集合并到一个程序集中。

  2. 您可以将辅助refence添加到您的解决方案中,即使您没有使用它,也会将其复制到您的bin文件夹。

  3. 创建另一个在编译后运行的目标,将缺少的程序集复制到文件夹

  4. 希望这有帮助。

    伊恩