{"id":138,"date":"2018-08-27T00:00:00","date_gmt":"2018-08-27T07:00:00","guid":{"rendered":"http:\/\/devblogs.microsoft.com\/nuget\/introducing-source-code-link-for-nuget-packages"},"modified":"2018-08-27T00:00:00","modified_gmt":"2018-08-27T07:00:00","slug":"introducing-source-code-link-for-nuget-packages","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/introducing-source-code-link-for-nuget-packages\/","title":{"rendered":"Introducing Source Code Link for NuGet packages"},"content":{"rendered":"<p>NuGet.org now supports surfacing source code repository link for NuGet packages. This will enable package authors to surface both the project&#8217;s website and the source repository using the <code>projectUrl<\/code> and the <code>repository<\/code> properties respectively instead of having to choose between the two using just the <code>projectUrl<\/code> property. The nuspec has supported the <code>repository<\/code> property for a while and today more than 16,000 packages contain this property. We have now come a full circle by surfacing this information on the package details page (on NuGet.org). This is how it looks for the <a href=\"https:\/\/www.nuget.org\/packages\/Newtonsoft.Json\/\">Newtonsoft.Json<\/a> package: <img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/49\/2019\/05\/source-code-example.png\" alt=\"Source Code\" \/> In this post, I would like to elaborate on the different ways to light up this feature for your packages.<\/p>\n<h3>Using <code>nuspec<\/code><\/h3>\n<p>If you are using a <code>nuspec<\/code> file for packaging, you will need to add a repository tag within your nuspec. For example, take a look at <a href=\"https:\/\/github.com\/nunit\/nunit\/blob\/master\/nuget\/framework\/nunit.nuspec#L11\">NUnit&#8217;s nuspec<\/a>:   <!-- .. snipped ... --><\/p>\n<pre><code>      &lt;!-- Add this line and making the URL targets your project --&gt; \n      &lt;repository type=\"git\" url=\"https:\/\/github.com\/nunit\/nunit\" \/&gt;\n\n      &lt;!-- .. snipped ... --&gt; \n   &lt;\/metadata&gt; \n&lt;\/package&gt;\n<\/code><\/pre>\n<h3>Using project file<\/h3>\n<p>If you create your NuGet package directly with a project file, you will need to add a <code>RepositoryUrl<\/code> and a <code>RepositoryType<\/code> to the project file to enable this new feature on your package. Here&#8217;s an example on how <a href=\"https:\/\/github.com\/restsharp\/RestSharp\/blob\/develop\/RestSharp\/RestSharp.csproj#L8\">RestSharp<\/a> implements it directly within their <code>csproj<\/code>.   <!-- .. snipped ... --><\/p>\n<pre><code>    &lt;RepositoryUrl&gt;https:\/\/github.com\/restsharp\/RestSharp.git&lt;\/RepositoryUrl&gt; \n    &lt;RepositoryType&gt;git&lt;\/RepositoryType&gt; \n    &lt;!-- .. snipped ... --&gt; \n   &lt;\/PropertyGroup&gt; \n   &lt;!-- .. snipped ... --&gt; \n&lt;\/Project&gt;\n<\/code><\/pre>\n<h3>Using SourceLink<\/h3>\n<p><a href=\"https:\/\/github.com\/dotnet\/sourcelink\">SourceLink<\/a> enables source debugging directly within your .NET Core packages. At the same time, it also inserts the repository attribute in your project to have the link show up on the NuGet package&#8217;s details page. To use it, you need to add the following to your <code>csproj<\/code> file.<\/p>\n<pre class=\"highlight\"><code>&lt;PropertyGroup&gt;\n    &lt;!-- Optional: Publish the repository URL in the built .nupkg (in the NuSpec &lt;Repository&gt; element) --&gt;\n    &lt;PublishRepositoryUrl&gt;true&lt;\/PublishRepositoryUrl&gt;\n&lt;\/PropertyGroup&gt;\n\n&lt;ItemGroup&gt;\n  &lt;!-- For GitHub --&gt;\n  &lt;PackageReference Include=\"Microsoft.SourceLink.GitHub\" Version=\"1.0.0-beta-63127-02\" PrivateAssets=\"All\"\/&gt;\n\n  &lt;!-- For Visual Studio Team Services --&gt;\n  &lt;PackageReference Include=\"Microsoft.SourceLink.Vsts.Git\" Version=\"1.0.0-beta-63127-02\" PrivateAssets=\"All\"\/&gt;\n\n  &lt;!-- For Team Foundation Server --&gt;\n  &lt;PackageReference Include=\"Microsoft.SourceLink.Tfs.Git\" Version=\"1.0.0-beta-63127-02\" PrivateAssets=\"All\"\/&gt;\n  &lt;SourceLinkTfsGitHost Include=\"tfs-server-name\" VirtualDirectory=\"tfs\"\/&gt;\n\n  &lt;!-- For GitLab --&gt;\n  &lt;PackageReference Include=\"Microsoft.SourceLink.GitLab\" Version=\"1.0.0-beta-63127-02\" PrivateAssets=\"All\"\/&gt;\n\n  &lt;!-- For BitBucket --&gt;\n  &lt;PackageReference Include=\"Microsoft.SourceLink.Bitbucket.Git\" Version=\"1.0.0-beta-63127-02\" PrivateAssets=\"All\"\/&gt;\n\n&lt;\/ItemGroup&gt;<\/code><\/pre>\n<p>For example, you can refer to the <a href=\"https:\/\/github.com\/JamesNK\/Newtonsoft.Json\/blob\/master\/Src\/Newtonsoft.Json\/Newtonsoft.Json.csproj#L24,L38\">Newtonsoft.Json&#8217;s implementation<\/a>.<\/p>\n<h3>Using Cake Build<\/h3>\n<p>Many open source projects use <a href=\"https:\/\/cakebuild.net\/\">Cake Build<\/a> to package their projects. Here\u2019s how you need to change your <code>NuGetPackSettings<\/code> to allow the source code repository link to be surfaced on NuGet.org:<\/p>\n<pre class=\"highlight\"><code>var nuGetPackSettings = new NuGetPackSettings\n    {\n        \/\/ snipped\n        Repository = new NuGetRepository {\n                Type = \"git\",\n                Url = \"https:\/\/github.com\/org\/repository\"\n            }\n        \/\/ snipped\n    };<\/code><\/pre>\n<h3>Conclusion<\/h3>\n<p>With these small changes to your packaging process, you will quickly get a source code link next to your project. You won&#8217;t have to choose between your project page or your project repository anymore. For more information on how nuspec and csproj properties are mapped, look at <a href=\"https:\/\/docs.microsoft.com\/en-us\/nuget\/reference\/msbuild-targets#pack-target\/\">our documentation<\/a>. If you want to reach out to us, you can either <a href=\"https:\/\/github.com\/NuGet\/Home\/issues\/new\">create a new GitHub issue<\/a> or tag <a href=\"https:\/\/twitter.com\/nuget\">@nuget<\/a> in your tweets.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>NuGet.org now supports surfacing source code repository link for NuGet packages. This will enable package authors to surface both the project&#8217;s website and the source repository using the projectUrl and the repository properties respectively instead of having to choose between the two using just the projectUrl property. The nuspec has supported the repository property for [&hellip;]<\/p>\n","protected":false},"author":41506,"featured_media":56238,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[7933,7874,7931],"tags":[],"class_list":["post-138","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-feature-announcement","category-nuget","category-nuget-org"],"acf":[],"blog_post_summary":"<p>NuGet.org now supports surfacing source code repository link for NuGet packages. This will enable package authors to surface both the project&#8217;s website and the source repository using the projectUrl and the repository properties respectively instead of having to choose between the two using just the projectUrl property. The nuspec has supported the repository property for [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/41506"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=138"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/138\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/56238"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}