1

I have installed VS 2017 and started building my solution with MSBuild 15. Immediately I notice that none of my before.{SolutionName}.sln.targets files are loaded.

I checked with ProcMon and the files are open and read without errors. But none of their actions are run.

Has anyone faced this situation? Any help is welcome.

EDIT 1

Here is my file:

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Restore">
  <Target Name="Restore" BeforeTargets="Build;Rebuild">
    <MSBuild Projects=".nuget\NuGet.Targets" Targets="RestoreSolutionPackages" Properties="SolutionFile=..\$(MSBuildProjectName);NuGetVerbosity=$(NuGetVerbosity)"/>
  </Target>
</Project>

It is working in VS 2015, but stopped working in VS 2017.

mark
  • 59,016
  • 79
  • 296
  • 580

1 Answers1

2

I figured out what is the problem. VS 2017 introduced a new target into the generated sln.metaproj file - Restore and this target overshadowed my own target in the before.{SolutionFile}.sln.targets file.

Once I renamed the target to MyRestore it worked again.

Wasted 3 hours on it :-(.

mark
  • 59,016
  • 79
  • 296
  • 580
  • Yup, normally I'm opposed to anything which reeks of Hungarian notation etc but in case of msbuild we tend to prefix names to avoid problems like these because they can be hard to track down. Note in case of a target I think a detailed build log says 'overriding target XXX with target XXX from fileYYY' so at least that can be traced. – stijn Oct 29 '18 at 09:48
  • Do note that for projects using PackageReference, you should do the nuget restore and build in separate invocations. msbuild 15 has a new `-restore` command line option that you could use instead. the important part is to make it clear file content caches of files that nuget generates. – Martin Ullrich Oct 29 '18 at 15:56
  • Our projects are built by both MSBuild 15 and MSBuild 14, so no MSBuild 15 features are used currently. – mark Oct 29 '18 at 21:31