Reputation: 14763
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?
Upvotes: 11
Views: 4668
Reputation: 5048
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" />
Upvotes: 0
Reputation: 2261
Just throwing this out here in case someone else faces this issue again. It seems that when you install MSBuildCommunityTasks via NuGet, a .build folder is added to the solution, which is recommended to be checked-in with source code. However, the MSBuild.Community.Tasks.targets file has a <MSBuildCommunityTasksPath>
element, which points to c:\Program Files(x86) folder, which is incorrect. This folder is valid when you install the MsBuildCommunityTasks using an MSI. This is invalid in case of Nuget, which installs the MsBuildCommunityTasks in the packages folder of your solution. So I ended up modifying the .targets file, and changed MSBuildCommunityTasksPath
to point to:
<MSBuildCommunityTasksPath>$(SolutionDir)\packages\MSBuildTasks.1.4.0.56\tools</MSBuildCommunityTasksPath>
Still no dice. So finally, I just edited by web project file, and changed the Import element for MSBuildCommunityTasks to this:
<Import Project="$(SolutionDir)\packages\MSBuildTasks.1.4.0.56\tools\MSBuild.Community.Tasks.Targets"/>
This works, since it directly tells the project to look for the .Targets file in the packages folder. Be aware, that if you upgrade the MSBuildTasks version, you will have to change the Import element. I am an MsBuild noob, so if someone can tell me how to automate this, it would be great!
Upvotes: 5
Reputation: 1109
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.
Upvotes: 6