Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing MSBuildTasks from Nuget package

Tags:

nuget

msbuild

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?

like image 698
Mike Cole Avatar asked Aug 02 '12 19:08

Mike Cole


1 Answers

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.

like image 183
redwyre Avatar answered Nov 01 '22 15:11

redwyre