msbuildmonomsbuild-taskxbuild

Using Microsoft.Build.Tasks in msbuild + xbuild


I have the following custom inline task that works in a windows build environment:

<UsingTask
    TaskName="Name"
    TaskFactory="CodeTaskFactory"
    AssemblyFile="C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Build.Tasks.v4.0.dll">
    <ParameterGroup>
        ...
    </ParameterGroup>
    <Task>
        <Code Type="Fragment" Language="cs">
            ...
        </Code>
    </Task>
</UsingTask>

I want this to work with xbuild also. This won't work obviously as the path is windows specific so I also tried using AssemblyName="Microsoft.Build.Tasks" which also didn't work.

So how should I reference Microsoft.Build.Tasks in my custom task in a way that would work for both msbuild and xbuild?


Solution

  • Using AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll" solved the problem.

    Looks like $(MSBuildToolsPath) is set to whatever is appropriate depending on the running platform so it will always work. Also I had to use v12.0 specifically, v4.0 didn't work.