5

I have a project which has a NuGet package called MSBuildTasks installed. It installs two files: MSBuild.Community.Tasks.targets and MSBuild.Community.Tasks.dll to the .build directory within the solution directory. This package reference has been added to the packages.config file in that project directory so that when I build the project (and with the NuGet package restore settings enabled) it will restore the package which is great because then I can distribute the source to other developers and build it on our build server without any missing files...

However, the problem is that when NuGet restores the package, it doesn't restore these two files to the expected location it was originally in when I first installed it with the Install-Package MSBuildTasks command, which was in to the $(SolutionDir)\.build directory. Instead, it has installed it to the $(SolutionDir)\packages\MSBuildTasks.1.4.0.78\tools directory, so now if I wish to include the MSBuild.Community.Tasks.targets file, I must reference this path absolutely in my .csproj or other .targets file. This presents a problem since the version number will undoubtedly change, requiring manual work to correct.

Is there some way that I can restore the MSBuildTasks .targets and .dll files to the original location of $(SolutionDir)\.build where it first installs to? The current behaviour of restoring in to the packages directory, while it makes sense for other packages, seems like a bug for this particular package since I will not be able to know the version number of the directory to include in my other .targets or .csproj files.

Aaron Cunnington
  • 1,631
  • 2
  • 15
  • 23

2 Answers2

7

NuGet restore will only download files to the packages directory. It will not make any other modifications.

Looking at the MSBuildTasks NuGet package the files added to the $(SolutionDir)\.build are added by a PowerShell script. This PowerShell script will not be run when restoring the NuGet package.

You should add the $(SolutionDir)\.build to your source control repository.

Matt Ward
  • 47,057
  • 5
  • 93
  • 94
  • 1
    But doesn't checking in the DLLs defeat the purpose of using a package manager like NuGet in the first place? – Dov Jan 12 '17 at 15:53
  • If the NuGet package adds files that would not be restored then the simplest solution is to add those particular files to source control. An alternative would be a slightly more complicated pre-build process where you restore and then you reinstall the MSBuildTasks NuGet package. Or the NuGet package itself is changed to not require these files. – Matt Ward Jan 13 '17 at 16:13
  • 1
    It appears this PowerShell script has been removed since version 1.5, yet the 'Getting Started' guide still suggests to use the `.build` folder. I've raised an [issue](https://github.com/loresoft/msbuildtasks/issues/258). – Neo Mar 29 '17 at 17:24
  • @Neo I've gave an answer on the GitHub issue but I'll add it here in case it helps someone: – lcornejo Aug 29 '17 at 21:07
1

With the newer versions 1.5+ the Nuget package doesn't install itself in the solution directory; this worked for me though:

<PropertyGroup>
    <MSBuildCommunityTasksPath>$(USERPROFILE)\.nuget\packages\msbuildtasks\1.5.0.235\tools</MSBuildCommunityTasksPath>
</PropertyGroup>

It does involved adding the version, but if someone knows a way to remove having to update the version on the path when you update the package that would be awesome.

lcornejo
  • 79
  • 4