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

发布于 2024-09-18 14:46:11 字数 4477 浏览 10 评论 0原文

我写了一个 MsBuild 任务:MyTask。在我的解决方案中,我有任务项目和其他项目。 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\ 来解决这个问题,但我不想这样做,因为它会在构建其他项目时触发问题(赢了' 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>

I wrote a MsBuild Task : MyTask. In my solution, I have the Task project and others projects. MyTask references a project (say ProjA) which references third assemblies, say (dep1 and dep2).

The projects all builds well and I have the outputs in one directory (Compil). In this directory i have all the dll's I want : MyTask.dll, ProjA.dll, dep1.dll, dep2.dll and others.

In my MsBuild file i include the custom task assembly with :

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

Then I call a task of the MyTask assembly. The call is well executed but MsBuild complains about not finding the dep1 and dep2 assemblies (although they are in the same directory) :

error : Could not load file or assembly 'dep1, Version=2.0.0.0, Culture=neutral,PublicKey Token=9109c11469ae1bc7' or one of its dependencies. The system cannot find the file specified.

I can solve this problem by copying dep1.dll and dep2.dll to c:\windows\microsoft .net\framework\v4.0\ but I don't want to do this because it triggers problems when building other projects (won't copy the dep1.dll and dep2.dll to the output directory...).

Has anybody the same problem, or better, a solution?


EDIT

Here is the output of 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.

And If I copy MsBuild.exe in the directory where all my dll are, it works fine...
MsBuild does not seem to look for dep1.dll and dep2.dll in my Compil directory even if it finds ProjA.dll within...


EDIT

As to how my bindings are done :
MyTask references the ProjA Project by :

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

ProjA references the two dependencies by

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我ぃ本無心為│何有愛 2024-09-25 14:46:11

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

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

编辑:部分绑定可能是原因。您是否使用 Assembly.Load 来使用 ProjA?从您提供的日志来看,它似乎无法加载 ProjA - 它甚至还不足以尝试加载 dep1 或 dep2。

You might try the Fusion Log Viewer (fuslogvw.exe, installed with VisualStudio) to see which paths are being searched for the assemblies. You may find another folder that can be used instead.

If dep1 and dep2 are third-party assemblies or internal ones that won't change, you could always throw them in the GAC. This is something I generally avoid on a build server, but if you are only using them for build helpers and not production installs it shouldn't be an issue.

Edit: The partial bind might be the cause. Are you using Assembly.Load to use ProjA? From the logs you provided, it looks like it is failing to load ProjA - it is not getting far enough to even try loading dep1 or dep2.

软糯酥胸 2024-09-25 14:46:11

我可以建议一些解决方法。

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

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

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

希望这有帮助。

伊恩

There are a couple of work arounds that I could sugest.

  1. ILMerge this will allow you merge several Assemblies together, into one assembly.

  2. You can add the secondary refence to your solution even though you are not using it, this would copy it to your bin folder.

  3. create another Target to run after the compile to copy the missing Assembly to the folder

Hope this helps.

Iain

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文