2012-02-26 61 views
14

我正在使用新的MSBuild内联任务来利用Microsoft.Web.Publishing.Tasks.dll程序集中的TransformXml(XDT变换)。MSBuild内联任务 - 参考非标准Microsoft程序集

这里就是我的任务(剪断)看起来像:,

<Task> 
    <Reference Include="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll"/> 
    <Reference Include="System.Xml" /> 
    <Using Namespace="System"/> 
    <Using Namespace="System.Linq"/> 
    <Using Namespace="System.IO" /> 
    <Using Namespace="System.Xml"/> 
    <Using Namespace="Microsoft.Web.Publishing.Tasks"/> 
    <Code Type="Fragment" Language="cs">...</Code> 
</Task> 

编译没有和DLL加载,但在执行时,因为它试图找到它是应用平台的路径装配失败:C:\Windows\Microsoft.NET\Framework\v4.0.30319。我会期待它看到我给它的道路。

融合日志显示此:

=== Pre-bind state information ===\r 
    LOG: User = xxx\Kamran\r 
    LOG: DisplayName = Microsoft.Web.Publishing.Tasks, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 
    (Fully-specified)\r 
    LOG: Appbase = file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/\r 
    LOG: Initial PrivatePath = NULL\r 
    Calling assembly : (Unknown).\r 
    ===\r 
    LOG: This bind starts in default load context.\r 
    LOG: Using application configuration file: C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe.Config\r 
    error MSB4018: LOG: Using host configuration file: \r 
    error MSB4018: LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.\r 
    error MSB4018: LOG: Post-policy reference: Microsoft.Web.Publishing.Tasks, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\r 
    error MSB4018: LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Microsoft.Web.Publishing.Tasks.DLL.\r 
    error MSB4018: LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Microsoft.Web.Publishing.Tasks/Microsoft.Web.Publishing.Tasks.DLL.\r 
    error MSB4018: LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Microsoft.Web.Publishing.Tasks.EXE.\r 
    error MSB4018: LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Microsoft.Web.Publishing.Tasks/Microsoft.Web.Publishing.Tasks.EXE.\r 

有什么办法解决这一问题或将我不得不创建任务组件呢?

+0

不正确关闭的错误报告:[MSBuild:用于内联任务引用的路径未被遵守](https://connect.microsoft.com/VisualStudio/feedback/details/768289/msbuild-path-used-for-直列任务引用是 - 不兑现)。重新提交:[MSBuild:用于内联任务引用的路径不受尊重(采取2)](https://connect.microsoft.com/VisualStudio/feedback/details/2285231) – Stijn 2016-01-26 11:04:16

+0

该错误已被Microsoft转载,您可以在https://github.com/Microsoft/msbuild/issues/594上关注其进展 – Stijn 2016-04-28 08:14:12

回答

3

我仍然想要一个真正的答案,但我能够解决这个问题,使用反射和只加载程序集。

你可以看到完整的源代码in my gist

0

根据本文Dzone:Web.config transformations必须正好的MSBuild文件的头部添加

<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll"/> 

。似乎MSBuild没有找到它,并试图从GAC加载

0

另一个解决方法是使用AppDomain.AssemblyResolve。但是,您必须在框架需要组装之前注册您的处理程序。

这可以通过将所有内容放入片段中的Action委托中来完成。另一种可能性是将'Code'元素的'Type'属性设置为'class'而不是'fragment'。

有关使用AssemblyResolve的信息,已有一篇关于stackoverflow的文章:How to add folder to assembly search path at runtime in .NET?

仍然不理想,但在我的情况下,比反思更清洁。