Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuke isn't packing referenced tools with global tool #437

Closed
krankenbro opened this issue Mar 12, 2020 · 2 comments
Closed

Nuke isn't packing referenced tools with global tool #437

krankenbro opened this issue Mar 12, 2020 · 2 comments
Assignees
Milestone

Comments

@krankenbro
Copy link

Description

http://www.nuke.build/docs/sharing-builds/global-tools.html

One great advantage that NUKE implements, is that all tool references will be automatically packed with the global tool. That means that package references having a ./tools folder, like GitVersion or xunit.runner.console, are automatically part of the global tool package. This makes the build self-contained.

Actually after dotnet pack we have only the tool packed without the referenced packages

Steps to reproduce

  1. add to csproj:
    image

2 dotnet pack

Relevant log output

image

@cmenzi
Copy link
Contributor

cmenzi commented Mar 12, 2020

Yes, I've encountered the same issue. This is the behavior of NuGet. See NuGet/Home#9132 (comment)

I've achieved it by repacking the NuGet package after pack.

What I did I created a .props where the package references are defined with a Pack=true attribute. You can also use your .csproj, but I use the .props file, because I use share build with NuGet package instead of GlobalTool.

So, I can inject some properties into _build.csproj via package updates.

Here is how I did it:

  1. Get the package after dotnet pack
  2. Extract the nupkg(zip)
  3. Add all dependencies to with the Pack attribute to nuspec file with exclude=All (development dependency), I think don't need that, because you also need those dependencies during runtime.
  4. Do another dotnet pack, but now with the modified NuspecFile file
var nugetPackage = Glob.Files(ArtifactsDirectory, "*.nupkg").NotEmpty().Single();
var propsFile = Glob.Files(BuildAssemblyDirectory, "*.props").NotNull().Single();
var propsContent = XDocument.Load(BuildAssemblyDirectory / propsFile);
var packageReferencesToAddToNuspec = propsContent.Descendants("PackageReference").Where(x => x.Attribute("Pack").Value == "True");

var extractedPackageDir = TemporaryDirectory / nugetPackage;
UncompressZip(ArtifactsDirectory / nugetPackage, extractedPackageDir);

var nuspecFile = Glob.Files(extractedPackageDir, "*.nuspec").NotEmpty().Single();
var nuspecDocument = XDocument.Load(extractedPackageDir / nuspecFile);
var namespaceName = nuspecDocument.Root.GetDefaultNamespace().NamespaceName;

var dependenciesElementName = XName.Get("dependencies", namespaceName);
var groupElementName = XName.Get("group", namespaceName);

var groupElement = nuspecDocument.Descendants(dependenciesElementName).Single().Element(groupElementName);

foreach (var packageReference in packageReferencesToAddToNuspec)
{
    var dependencyElement = new XElement(XName.Get("dependency", namespaceName));
    dependencyElement.Add(new XAttribute("id", packageReference.Attribute("Include").Value), new XAttribute("version", packageReference.Attribute("Version").Value), new XAttribute("exclude", "All"));
    groupElement.Add(dependencyElement);
}

nuspecDocument.Save(extractedPackageDir / nuspecFile);

DotNetPack(_ => _
    .SetProject(MainProject)
    .SetProperty("NuspecFile", extractedPackageDir / nuspecFile)
    .SetOutputDirectory(ArtifactsDirectory)
    .SetProperty("NoWarn", "$(NoWarn)%3BNU5048"));

@matkoch matkoch added this to the v0.24.5 milestone Mar 17, 2020
@matkoch matkoch closed this as completed Mar 21, 2020
@lock
Copy link

lock bot commented Apr 5, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Apr 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants