Ideally, we would want to be able to suppress the package reference in the manner that you have. In practice, this unfortunately doesn't work because the package reference is also declared in the derived files created by the Nuget package restore (i.e. project.assets.json) and we don't have a way to manipulate these files with conditions.
We need to find a different workaround.
One way might be to override the XmlDoc2CmdletDocCommand property with something benign.
Try using your 'Custom build properties' NCrunch configuration setting to set this property to something like 'echo Do nothing'. In this way, the command will still run, but it will do nothing.
<PropertyGroup Condition="'$(NCrunch)' == '1'">
<XmlDoc2CmdletDocCommand>echo Do nothing</XmlDoc2CmdletDocCommand>
</PropertyGroup>
My guess is, it is probably an order problem, cause that is how MSBuild works. Last definition wins.
So I would expect that when NCrunch builds, the property XmlDoc2CmdletDocCommand is first set when the csproj is read, then the NuGet packages target file is read and everything is back to the normal value.
So I would expect that when NCrunch builds, the property XmlDoc2CmdletDocCommand is first set when the csproj is read, then the NuGet packages target file is read and everything is back to the normal value.
Yes. Sadly this was much simpler under the old .NET Framework, because we could control the order in which targets are included in the build file. Under the new CPS system, MSBuild implicitly declares the imports after the .csproj, making it hard to override them.
It's still possible though. You can just use the 'BeforeTargets' parameter to declare your own target that injects itself into the build sequence to override the property after its default is already set:
<PropertyGroup>
<XmlDoc2CmdletDocCommand>echo Do nothing</XmlDoc2CmdletDocCommand>
</PropertyGroup>
</Target>
In theory, the properties set by the 'Custom build properties' setting should override properties declared in the project file and included targets. In practice, MSBuild is a strange machine that has changed a great deal over the years. Maybe this particular approach doesn't work on your setup.
Now as I read your solution, it looks so simple ;)
Yes overriding the property not in the project file, but just before calling the task does the trick.
I still hope you find a better solution to ignore packages for NCrunch in the future, but for now I am happy that I have a working setup generating the output in case of a build, but also allowing me to write and run my tests in conjunction with NCrunch.
I also made a feature request in the RedGate github repository for suppressing the targets, e.g. if you only want the documentation generated only for Release builds.
E.g. if you dont have GenerateDocumentationFile = true, the EXE is also called, but fails in absence of an Xml file to transform.
But I cannot complain. It is a free tool doing everything I want in most cases.