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

Get License Information for Dependency - SDK-Style #9

Closed
wgnf opened this issue Nov 16, 2021 · 10 comments · Fixed by #26
Closed

Get License Information for Dependency - SDK-Style #9

wgnf opened this issue Nov 16, 2021 · 10 comments · Fixed by #26
Assignees
Labels
enhancement New feature or request format:sdk-style A csproj that is in the SDK-Style-Format
Projects

Comments

@wgnf
Copy link
Owner

wgnf commented Nov 16, 2021

  • License Type
  • License Text

idk how this might work, i know of these locations where Licenses might be:

  • NuGet-Property: PackageLicenseExpression
  • NuGet-Property: PackageLicenseUrl
  • LICENSE file embedded in NuGet
@wgnf wgnf added the enhancement New feature or request label Nov 16, 2021
@wgnf wgnf added this to To do in Backlog via automation Nov 16, 2021
@wgnf
Copy link
Owner Author

wgnf commented Nov 16, 2021

To download a NuGet Package maybe use this command:

dotnet add package <NAME> -v -n --prerelease -f <TARGET FRAMEWORK> --package-directory <PACKAGE_DIRECTORY>

On a dummy project and use PACKAGE_DIRECTORY as a point to refer to the downloaded package

More information see here

@wgnf
Copy link
Owner Author

wgnf commented Nov 16, 2021

But what's with a possible nuget.config?
For that I might need to add this dummy project in the actual source structure...
But I also want to be non-invasive 🤔

@wgnf
Copy link
Owner Author

wgnf commented Nov 16, 2021

OH!

Maybe dotnet restore --packages <PACKAGE_DIRECTORY> might work?

This'll definitely utilize everything that there is (nuget.config, cached packages on the system, ...) and will be offered for the .NET (Core) CLI

Does this work non-SDK-Style projects too?

@wgnf
Copy link
Owner Author

wgnf commented Nov 17, 2021

Yes, dotnet restore works. Following needs to be done for downloading packages:

  • Non-SDK-Style: nuget restore -Force -OutputDirectory <FOLDER> -Recursive
  • SDK-Style: dotnet restore --packages <FOLDER> --force /p:DisableImplicitNuGetFallbackFolder=true

There are some catches, though:

  • Structure:
    • dotnet restore: Package-Name (lower-case) --> Version --> All data (nupkg, nuspec, license, ...)
    • nuget restore: Package-Name + Version (i.e. Autofac.4.9.4) --> Some data (nupkg, license, ...)

@wgnf
Copy link
Owner Author

wgnf commented Nov 17, 2021

Getting the License-Text should also be "two-stepped"

  1. Is there a License already embedded in the NuGet-Package?
  2. Download from the URL-Source provided

Getting the License-Type should be done, by:

  1. Has the nuspec a "License Expression"?
  2. ...
  3. Get it from the internal/manually provided URL to Type Mapping
  4. Get it from the License-Text (Keywords, see Getting License Type by License Text #10)

@wgnf wgnf added the format:sdk-style A csproj that is in the SDK-Style-Format label Nov 17, 2021
@wgnf wgnf changed the title Get License Information for Dependency Get License Information for Dependency - SDK-Style Nov 17, 2021
@wgnf
Copy link
Owner Author

wgnf commented Nov 20, 2021

Yes, dotnet restore works. Following needs to be done for downloading packages:

  • Non-SDK-Style: nuget restore -Force -OutputDirectory <FOLDER> -Recursive
  • SDK-Style: dotnet restore --packages <FOLDER> --force /p:DisableImplicitNuGetFallbackFolder=true

There are some catches, though:

  • Structure:
    • dotnet restore: Package-Name (lower-case) --> Version --> All data (nupkg, nuspec, license, ...)
    • nuget restore: Package-Name + Version (i.e. Autofac.4.9.4) --> Some data (nupkg, license, ...)

Problem with using restore is just that every package will be downloaded, even though we might just need a few, depending on the cache (see #1) and additionally restore might take pretty long in some cases (idk why)

Maybe looking for the package in the package file-package-sources

  • %USERPROFILE%/dotnet/packages (or sth similar)
  • packages folder in case of non SDK style
  • ...

And then downloading directly might be a better option

Or really just using dotnet add or something on a dummy project (inside the obj folder maybe) for packages that are really needed might be the better option

@wgnf
Copy link
Owner Author

wgnf commented Nov 20, 2021

Maybe there's a package that can do this? 🤔

@wgnf
Copy link
Owner Author

wgnf commented Dec 19, 2021

These are the ways licenses can be specified (as far as i found out so far) - information are in the .nuspec file:

1:

2:

  • license tag with expression attribute (/package/metadata/license[@expression])
  • licenseUrl tag (/package/metadata/licenseUrl)
  • no license file in downloaded content
  • get raw license text from specified url (licenseUrl tag)
  • get license type from license tag

3:

  • license tag with expression attribute (/package/metadata/license[@expression])
  • licenseUrl tag (/package/metadata/licenseUrl)
  • license file in downloaded content (file containing "license" in the filename)
  • get raw license text from license file
  • get license type from license tag

4:

5:

@wgnf
Copy link
Owner Author

wgnf commented Jan 3, 2022

Best way to do it would be to have a number of sources:

... so that we get more and more information with each step/source, until we eventually, hopefully, have everything that we need

@wgnf wgnf self-assigned this Jan 3, 2022
@wgnf
Copy link
Owner Author

wgnf commented Jan 4, 2022

Other TODOs:

  • Change PackageReference to have a LicenseInformation object? 🤔
  • dotnet package list also provides ProjectReferences which cannot be downloaded... this needs to be fixed

@wgnf wgnf closed this as completed in #26 Jan 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request format:sdk-style A csproj that is in the SDK-Style-Format
Projects
Archived in project
Backlog
To do
Development

Successfully merging a pull request may close this issue.

1 participant