Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSBuild Inline Task - Reference non-standard Microsoft assemblies

I am using the new MSBuild Inline Task to leverage the TransformXml (XDT Transform) in the Microsoft.Web.Publishing.Tasks.dll assembly.

Here's what my task (snipped) looks like:

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

This compiles fine and the DLL is loaded, however, when executed it fails because it is trying to find the assembly in the appbase path which is: C:\Windows\Microsoft.NET\Framework\v4.0.30319. I would have expected it to look at the path I gave it.

Fusion log shows this:

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

Is there any way to fix this or will I be forced to create a task assembly instead?

like image 345
kamranicus Avatar asked Feb 26 '12 17:02

kamranicus


1 Answers

I would still like a real answer to this, but I was able to workaround this issue using reflection and just loading the assembly.

You can see the full source in my gist.

like image 172
kamranicus Avatar answered Sep 20 '22 16:09

kamranicus