代码之家  ›  专栏  ›  技术社区  ›  Benjamin Baumann

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

  •  6
  • Benjamin Baumann  · 技术社区  · 14 年前

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

    所有的项目都构建得很好,我在一个目录(Compil)中有输出。在这个目录中,我有我想要的所有dll:我的任务.dll, 项目.dll、dep1.dll、dep2.dll等。

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

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

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

    我可以通过将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似乎没有在我的Compil目录中查找dep1.dll和dep2.dll,即使找到了项目.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 回复  |  直到 14 年前
        1
  •  2
  •   Pedro    14 年前

    你可以试试Fusion日志查看器(fuslogvw.exe文件,与VisualStudio一起安装),以查看正在搜索程序集的路径。您可以找到另一个可以替代的文件夹。

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

    编辑:编辑 partial bind 可能是原因。你在用吗装配。负载使用ProjA?从您提供的日志来看,似乎无法加载ProjA—甚至无法尝试加载dep1或dep2。

        2
  •  0
  •   Iain    14 年前

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

    1. ILMerge

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

    希望这有帮助。

    伊恩

    推荐文章