EWSoftware / SHFB

Sandcastle Help File Builder (SHFB). A standalone GUI, Visual Studio integration package, and MSBuild tasks providing full configuration and extensibility for building help files with the Sandcastle tools.
Other
2.19k stars 367 forks source link

Support for Nuget Central Package Management #1057

Closed WolfgangHG closed 1 week ago

WolfgangHG commented 4 months ago

It seems Sandcastle cannot resolve dependencies if "Nuget Central Package Management" is used (https://learn.microsoft.com/en-us/nuget/consume-packages/central-package-management)

See attached sample: in the solution root, a file "Directory.Packages.props" enables this feature and defines a list of nuget packages that are available inside this solution and the versions of these packages:

<Project>
  <PropertyGroup>
    <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
  </PropertyGroup>
  <ItemGroup>
    <PackageVersion Include="Aspose.Cells" Version="24.3.0" />
  </ItemGroup>
</Project>

In each csproj file, the necessary packages are defined without versions:

    <PackageReference Include="Aspose.Cells" />

When building the Sandcastle project in attached sample SandcastleNuget.zip, this results in an error:

MRefBuilder : error : Unresolved assembly reference: Aspose.Cells (Aspose.Cells, Version=24.3.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56) required by SandcastleNugetLib [C:\Temp\SandcastleNuget\SandcastleDoc\Help\Working\GenerateRefInfo-7f8e79e1-7858-4d26-ae57-03abe7d4c3a7.proj]
    Last step completed in 00:00:01,2907
</buildStep>
<buildStep step="Failed">

SHFB: Error BE0043: Unexpected error detected in last build step.  See build log for details.
   at SandcastleBuilder.Utils.BuildEngine.TaskRunner.Run(String processFilename, String targetFile, String arguments) in C:\GH\SHFB\SHFB\Source\SandcastleBuilderUtils\BuildEngine\TaskRunner.cs:line 237
   at SandcastleBuilder.Utils.BuildEngine.BuildProcess.Build() in C:\GH\SHFB\SHFB\Source\SandcastleBuilderUtils\BuildEngine\BuildProcess.cs:line 997

I could workaround it by adding the "Wildcard Assembly References" plugin and let it point to the exact dll version in my Nuget cache:

<PlugInConfig id="Wildcard Assembly References" enabled="True">
  <configuration>
    <references>
      <reference path="C:\Users\USERNAME\.nuget\packages\aspose.cells\24.3.0\lib\net6.0\" wildcard="*.dll" recurse="true" />
    </references>
  </configuration>
</PlugInConfig>

Is there a better workaround?

EWSoftware commented 1 month ago

It's currently ignoring any project package references without a version attribute. I've updated it to keep them and, lacking a version, it will match it to the first package it can find by name alone. Since there shouldn't be multiple copies with conflicting versions within the same project, that should take care of the issue.

Zastai commented 2 weeks ago

@WolfgangHG Another workaround might be to add <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> to the projects being documented; that does make their bin folders bigger (because all dependencies are copied there).