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?
I recently set this up for resourcelib, using MSBuildTasks version 1.4.0.45. In this version adding it to the project resulted in the DLL being placed in a "Build" subdirectory, which looks like you need to check in. I tried to have it auto-download, but if it's referenced in a project file it needs to be there from the start.
To add it to the project, I used the following code:
<PropertyGroup>
<MSBuildCommunityTasksPath>$(MSBuildProjectDirectory)\Build</MSBuildCommunityTasksPath>
</PropertyGroup>
<Import Project="$(MSBuildCommunityTasksPath)\MSBuild.Community.Tasks.Targets"/>
Here MSBuildProjectDirectory
is being used so it can be built with MSBuild on the command line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With