Referencing MSBuildTasks from Nuget package

Viewed 4514

I'm trying to reference MSBuildTasks from an MSBuild file, and I'm unsure of how to do this when using NuGet for MSBuildTasks.

The reference says to use

<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>

when you have installed MSBuildTasks using the msi file. However, when installing from NuGet it puts it in a subfolder that contains version, so if I upgrade MSBuildTasks it will break the path in the build file. What is the best way to reference MSBuildTasks when its installed via NuGet?

3 Answers

At the moment, 1.4.0.128 creates the .build folder in the solution directory (for a framework project). The nuget package does not install properly to a .Net Core 3.1 project. I created a MsBuild.Community.Tasks 4.7.2 framework project within my solution and deployed the nuget package there. Now I should be able to invoke it from my .NetCore project as described in the readme:

<PropertyGroup>
    <MSBuildCommunityTasksPath>$(SolutionDir)\.build</MSBuildCommunityTasksPath>
</PropertyGroup>  

<Import Project="$(MSBuildCommunityTasksPath)\MSBuild.Community.Tasks.Targets" />
Related