ByteDev/ByteDev.DotNet

Provide RepositoryUrl and PackageLicenseFile for NuGet.org

Closed this issue · 3 comments

When I just wanted to quit due to no license and repository reference, I found in the documentation on NuGet.org the link to this repository, so it is would be advisable to add:

<PropertyGroup>
<RepositoryUrl Condition="'$(RepositoryUrl)' == ''">https://github.com/ByteDev/ByteDev.DotNet</RepositoryUrl>
<PackageLicenseFile Condition="'$(PackageLicenseFile)' == ''">LICENSE</PackageLicenseFile>
</PropertyGroup>

Yeah been meaning to look into license as it keeps giving warning. Will very soon, thanks.

Which kind of error? Here a working approach:

  1. Put your license at root, like you did.
  2. Write a Directory.Build.props at root level with content like
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- In any project in this folder you will see a only for msbuild visible "link" to root license file. -->
 <None Include="$(MSBuildThisFileDirectory)\LICENSE">
      <!-- We want it in the package. -->
      <Pack>True</Pack>
      <!-- We want it to be at in the root of the package, because nuget.org want it in exactly this way. The license path (you defined in PackageLicenseFile ) will be written the nuspec file in the package. -->
      <PackagePath></PackagePath>
    </None>

<PropertyGroup>
    <!-- Will be written to .nuspec of package. You only have use the path, which you have defined above -->
    <PackageLicenseFile Condition="'$(PackageLicenseFile)' == ''">LICENSE</PackageLicenseFile>
    <!-- EACH project when packed wil have this information in package. MSBuild does so only when you pack project. -->
    <RepositoryUrl Condition="'$(RepositoryUrl)' == ''">https://github.com/ByteDev/ByteDev.DotNet</RepositoryUrl>
    <!-- This works with any other property. https://docs.microsoft.com/de-de/dotnet/core/tools/csproj#nuget-metadata-properties -->
  </PropertyGroup>
</Project>
  1. You are done.

This works, because Directory.Build.props will be injected before each project you access by MSBuild. When you build a project in your root directory, MSBuild searches for the nearest Directory.Build.props.

Version 6.0.0 now on nuget.