我写了一个 MsBuild 任务:MyTask。在我的解决方案中,我有 Task 项目和其他项目。MyTask 引用了一个项目(比如 ProjA),该项目引用了第三个程序集,比如(dep1 和 dep2)。
这些项目都构建得很好,我将输出放在一个目录(编译)中。在这个目录中,我有我想要的所有 dll:MyTask.dll、ProjA.dll、dep1.dll、dep2.dll 等。
在我的 MsBuild 文件中,我包含自定义任务程序集:
<UsingTask AssemblyFile="..\Compil\MyTask.dll" TaskName="CreateSitesCss" />
然后我调用 MyTask 程序集的一个任务。该调用执行良好,但 MsBuild 抱怨找不到 dep1 和 dep2 程序集(尽管它们位于同一目录中):
错误:无法加载文件或程序集“dep1,版本=2.0.0.0,文化=中性,公共密钥令牌=9109c11469ae1bc7”或其依赖项之一。该系统找不到指定的文件。
我可以通过将 dep1.dll 和 dep2.dll 复制到 c:\windows\microsoft .net\framework\v4.0\ 来解决这个问题,但我不想这样做,因为它在构建其他项目时会引发问题(赢了t 将 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>