Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Ignore NuGet packages
Argamon
#1 Posted : Thursday, August 6, 2020 8:39:31 AM(UTC)
Rank: Member

Groups: Registered
Joined: 12/4/2018(UTC)
Posts: 12
Location: Germany

Thanks: 1 times
Was thanked: 2 time(s) in 2 post(s)
I have a library for PowerShell Cmdlets.

In this project I use the NuGet package XmlDoc2CmdletDoc.

Basically this adds a target to MSBuild calling a commandline tool.

Code:

    <Target Name="XmlDoc2CmdletDoc"
            AfterTargets="CopyFilesToOutputDirectory"
            Inputs="$(TargetPath)"
            Outputs="$(TargetPath)-Help.xml">
        <Exec Command="$(XmlDoc2CmdletDocCommand)" />
    </Target>


This commandline tool does not expect the NCrunch way of creating the output (but works as expected in a normal build).

In the end I dont want any documentation created during the NCrunch build, but I cannot modify the targets file of the NuGet package.

So I tried to modify my csproj file:
Code:

    <PackageReference Include="XmlDoc2CmdletDoc" Version="0.4.0-dotnetcore0000" Condition="'$(NCrunch)' != '1'">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>


But NCrunch still uses the NuGet package.

Any other (working) ways to ignore a NuGet package?
Remco
#2 Posted : Friday, August 7, 2020 12:45:15 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,123

Thanks: 957 times
Was thanked: 1286 time(s) in 1193 post(s)
Hi thanks for sharing this issue.

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.
Argamon
#3 Posted : Friday, August 7, 2020 9:01:36 AM(UTC)
Rank: Member

Groups: Registered
Joined: 12/4/2018(UTC)
Posts: 12
Location: Germany

Thanks: 1 times
Was thanked: 2 time(s) in 2 post(s)
I like your idea, but I cannot get it to work.

I did add this to my csproj file:

Code:

  <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.
Remco
#4 Posted : Friday, August 7, 2020 10:19:40 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,123

Thanks: 957 times
Was thanked: 1286 time(s) in 1193 post(s)
Argamon;14914 wrote:


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:

<Target Name="OverrideXmlDoc2CmdletDoc"
BeforeTargets="XmlDoc2CmdletDoc"
Condition="'$(NCrunch)' == '1'">

<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.
1 user thanked Remco for this useful post.
Argamon on 8/7/2020(UTC)
Argamon
#5 Posted : Friday, August 7, 2020 12:08:14 PM(UTC)
Rank: Member

Groups: Registered
Joined: 12/4/2018(UTC)
Posts: 12
Location: Germany

Thanks: 1 times
Was thanked: 2 time(s) in 2 post(s)
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.
1 user thanked Argamon for this useful post.
Remco on 8/7/2020(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.033 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download