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

Use csproj as pack input instead of nuspec #1119

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ The only feature currently supported is mapping of source files to the source re

## Prerequisites for .NET projects

Source Link supports classic .NET Framework projects as well as .NET SDK projects, that is projects that import `Microsoft.NET.Sdk` (e.g. like so: `<Project Sdk="Microsoft.NET.Sdk">`). The project may target any .NET Framework or .NET Core App/Standard version. All PDB formats are supported: Portable, Embedded and Windows PDBs.
Source Link supports classic .NET Framework projects as well as .NET SDK projects, that is projects that import `Microsoft.NET.Sdk` (e.g. like so: `<Project Sdk="Microsoft.NET.Sdk">`). The project may target .NET, .NET Framework or .NET Standard. All PDB formats are supported: Portable, Embedded and Windows PDBs.

[.NET Core SDK 2.1.300](https://www.microsoft.com/net/download/dotnet-core/sdk-2.1.300) or newer is required for .NET SDK projects. If building via desktop `msbuild` you'll need version 15.7 or higher.
[.NET 8 SDK](https://www.microsoft.com/net/download/dotnet/8.0) or newer is required for .NET SDK projects. If building via desktop `msbuild` you'll need version 16.0 or higher.

The following features are not available in projects that do not import `Microsoft.NET.Sdk`:
- Automatic inclusion of commit SHA in `AssemblyInformationalVersionAttribute`.
Expand All @@ -200,8 +200,6 @@ The VC++ linker supports `/SOURCELINK` [switch](https://docs.microsoft.com/en-us

## Known issues

- `EmbedUntrackedSources` does not work in Visual Basic projects that use .NET SDK: https://github.com/dotnet/sourcelink/issues/193 (fixed in Visual Studio 2019)
- Issue when building WPF projects with `/p:ContinuousIntegrationBuild=true`: https://github.com/dotnet/sourcelink/issues/91
- Issue when building WPF projects with embedding sources on and `BaseIntermediateOutputPath` not a subdirectory of the project directory: https://github.com/dotnet/sourcelink/issues/492

## PDB distributions
Expand All @@ -222,20 +220,20 @@ Keep in mind that including PDBs in the .nupkg increases the size of the package

- They do not support Windows PDBs (generated by VC++, or for managed projects that set build property `DebugType` to `full`)
- They require the library to be built by newer C#/VB compiler (Visual Studio 2017 Update 9).
- The consumer of the package also needs Visual Studio 2017 Update 9 debugger.
- The consumer of the package also needs Visual Studio 2022 or newer.
Comment on lines -225 to +223

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, neither NuGet restore nor the Visual Studio debugger is able to read symbols from snupkg, but NuGet.org indexes the symbols from uploaded snupkg files and provides them to debuggers via the symbol server protocol. Did nupkg.org change its symbol server so that it no longer works with VS2017? If not, what's the reason of this doc change?

- Not supported by [Azure DevOps Artifacts](https://azure.microsoft.com/en-us/services/devops/artifacts) service.

Consider including PDBs in the main package if it is not possible to use .snupkg for the above reasons.
For managed projects, consider switching to Portable PDBs by setting `DebugType` property to `portable`. This is the default for .NET SDK projects, but not classic .NET projects.

## Builds

Pre-release builds are available from Azure DevOps public feed: `https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json` ([browse](https://dev.azure.com/dnceng/public/_packaging?_a=feed&feed=dotnet8)).
Pre-release builds are available from Azure DevOps public feed: `https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet9/nuget/v3/index.json` ([browse](https://dev.azure.com/dnceng/public/_packaging?_a=feed&feed=dotnet9)).

[![Build Status](https://dnceng.visualstudio.com/public/_apis/build/status/SourceLink%20PR?branchName=main)](https://dnceng.visualstudio.com/public/_build/latest?definitionId=297?branchName=main)

## Experience in Visual Studio

The following screenshot demonstrates debugging a NuGet package referenced by an application, with source automatically downloaded from GitHub and used by Visual Studio 2017.
The following screenshot demonstrates debugging a NuGet package referenced by an application, with source automatically downloaded from GitHub and used by Visual Studio.

![sourcelink-example](https://user-images.githubusercontent.com/2608468/39667937-10d7dabe-5076-11e8-815e-935724b3a783.PNG)
111 changes: 111 additions & 0 deletions eng/BuildTask.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<!-- Copied from arcade with small modifications. -->
<Project>

<PropertyGroup>
<IncludeBuildOutput>false</IncludeBuildOutput>
<IsPackable>true</IsPackable>
<!-- Build Tasks should have this set per https://github.com/dotnet/arcade/blob/master/Documentation/CorePackages/Versioning.md#recommended-settings -->
<AutoGenerateAssemblyVersion>true</AutoGenerateAssemblyVersion>
<PackTasks Condition="'$(PackTasks)' == ''">true</PackTasks>
<TargetsForTfmSpecificContentInPackage Condition="'$(PackTasks)' == 'true'">$(TargetsForTfmSpecificContentInPackage);_AddBuildOutputToPackageCore;_AddBuildOutputToPackageDesktop</TargetsForTfmSpecificContentInPackage>
<DevelopmentDependency>true</DevelopmentDependency>
<!-- Some target frameworks declared in the dependencies group of the nuspec and the lib/ref folder do not have exact matches in the other location. -->
<NoWarn>$(NoWarn);NU5128</NoWarn>
</PropertyGroup>

<!--
Default to including all *.props and *.targets files
from the project directory into the NuGet package root
-->
<ItemGroup Condition="'$(EnableDefaultItems)' != 'false'">
<None Condition="'$(EnableDefaultNoneItems)' != 'false'"
Include="**/*.props;**/*.targets"
Pack="true"
PackagePath="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>

<ItemGroup>
<None Include="$(RepoRoot)License.txt" PackagePath="LICENSE.txt" Pack="true"/>
</ItemGroup>

<!-- Don't include assemblies that MSBuild ships with. -->
<ItemGroup>
<PackageReference Update="Microsoft.Build" Publish="false" />
<PackageReference Update="Microsoft.Build.Framework" Publish="false" />
<PackageReference Update="Microsoft.Build.Tasks.Core" Publish="false" />
<PackageReference Update="Microsoft.Build.Utilities.Core" Publish="false" />
<PackageReference Update="Microsoft.NET.StringTools" Publish="false" />
<PackageReference Update="System.Collections.Immutable" Publish="false" />
</ItemGroup>

<!-- Don't include assemblies that are provided by the SDK, next to MSBuild. -->
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and '$(SkipSDKInboxPublishExcludes)' != 'true'">
<PackageReference Update="Newtonsoft.Json" Publish="false" />
<PackageReference Update="NuGet.Commands" Publish="false" />
<PackageReference Update="NuGet.Common" Publish="false" />
<PackageReference Update="NuGet.Configuration" Publish="false" />
<PackageReference Update="NuGet.Frameworks" Publish="false" />
<PackageReference Update="NuGet.Packaging" Publish="false" />
<PackageReference Update="NuGet.ProjectModel" Publish="false" />
<PackageReference Update="NuGet.Versioning" Publish="false" />
</ItemGroup>

<!-- Don't include assemblies that are inbox in Desktop MSBuild -->
ViktorHofer marked this conversation as resolved.
Show resolved Hide resolved
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
<PackageReference Update="System.Buffers" Publish="false" />
<PackageReference Update="System.Memory" Publish="false" />
<PackageReference Update="System.Numerics.Vectors" Publish="false" />
<PackageReference Update="System.Reflection.Metadata" Publish="false" />
<PackageReference Update="System.Reflection.MetadataLoadContext" Publish="false" />
<PackageReference Update="System.Runtime.CompilerServices.Unsafe" Publish="false" />
<PackageReference Update="System.Security.Cryptography.Xml" Publish="false" />
<PackageReference Update="System.Text.Encodings.Web" Publish="false" />
<PackageReference Update="System.Text.Json" Publish="false" />
<PackageReference Update="System.Threading.Tasks.Dataflow" Publish="false" />
<PackageReference Update="System.Threading.Tasks.Extensions" Publish="false" />
<PackageReference Update="System.ValueTuple" Publish="false" />
</ItemGroup>

<ItemGroup>
<!--
Update all PackageReference items to default Publish to true.
This forces the publish output to contain the dlls.
-->
<PackageReference Update="@(PackageReference)">
<Publish Condition="'%(PackageReference.Publish)' == ''">true</Publish>
<PrivateAssets Condition="'%(PackageReference.Publish)' == 'false'">all</PrivateAssets>
</PackageReference>

<!--
Update all Reference items to have Pack="false"
This removes the frameworkDependency nodes from the generated nuspec
-->
<Reference Update="@(Reference)"
Pack="false" />
</ItemGroup>

<!-- Desktop MSBuild compatibilty -->
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
<PackageReference Update="System.Text.Json" Version="7.0.1" />
<PackageReference Update="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
<PackageReference Update="Microsoft.Extensions.DependencyModel" Version="7.0.0" />
<PackageReference Update="System.Collections.Immutable" Version="7.0.0" />
<PackageReference Update="System.Reflection.Metadata" Version="7.0.0" />
</ItemGroup>

<!-- Publish .NET assets and include them in the package under tools/net directory. -->
<Target Name="_AddBuildOutputToPackageCore" DependsOnTargets="Publish" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<ItemGroup>
<TfmSpecificPackageFile Include="$(PublishDir)**"
PackagePath="tools/net/%(RecursiveDir)%(FileName)%(Extension)"/>
</ItemGroup>
</Target>

<!-- Include .NET Framework build outputs in the package under tools/netframework directory. -->
<Target Name="_AddBuildOutputToPackageDesktop" Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
<ItemGroup>
<TfmSpecificPackageFile Include="$(OutputPath)**" PackagePath="tools/netframework/%(RecursiveDir)%(FileName)%(Extension)"/>
</ItemGroup>
</Target>

</Project>
9 changes: 2 additions & 7 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<Project>

<Import Project="Sdk.props" Sdk="Microsoft.DotNet.Arcade.Sdk" />

<PropertyGroup>
Expand All @@ -9,11 +10,5 @@

<IncludeSymbols Condition="'$(DebugType)' != 'embedded' and '$(UsingMicrosoftNoTargetsSdk)' != 'true'">true</IncludeSymbols>
</PropertyGroup>

<!--
Workaround for https://github.com/dotnet/sdk/issues/2232: GenerateDepsFile throws ArgumentException.
-->
<PropertyGroup Condition="'$(IsTestProject)' != 'true'">
<GenerateDependencyFile>false</GenerateDependencyFile>
</PropertyGroup>

</Project>
32 changes: 1 addition & 31 deletions src/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
<Project>

<Import Project="Sdk.targets" Sdk="Microsoft.DotNet.Arcade.Sdk" />

<!-- TODO: Remove when Arcade offers an in-built way to filter out anything other than NetCurrent: https://github.com/dotnet/arcade/issues/13390. -->
<PropertyGroup>
<TargetFrameworks Condition="'$(TargetFrameworks)' != '' and '$(DotNetBuildSourceOnly)' == 'true'">$(NetCurrent)</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<NuspecProperty Include="DesktopTfm=net472"/>
<NuspecProperty Include="CoreTfm=$(NetCurrent)" Condition="'$(DotNetBuildSourceOnly)' == 'true'"/>
<NuspecProperty Include="CoreTfm=$(NetMinimum)" Condition="'$(DotNetBuildSourceOnly)' != 'true'"/>
</ItemGroup>

<!--
Workaround for https://github.com/NuGet/Home/issues/6754: cyclic dependency.
-->
<PropertyGroup>
<_ProjectDefinedPackageId>$(PackageId)</_ProjectDefinedPackageId>
<PackageId>*fake_packageid_for_project_$(MSBuildProjectName)*</PackageId>
</PropertyGroup>
<Import Project="$(RepositoryEngineeringDir)BuildTask.targets" Condition="'$(IsBuildTaskProject)' == 'true'" />

<!--
Workaround for https://github.com/Microsoft/msbuild/issues/2527.
Expand All @@ -28,16 +10,4 @@
<ImplicitlyExpandNETStandardFacades Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">false</ImplicitlyExpandNETStandardFacades>
</PropertyGroup>

<!--
Workaround for cyclic package reference. PackageId is set to ain invalid value above (in evaluation phase to be picked up by Restore),
then updated to the actual value before Pack target and SourceLink source package generation target.
-->
<Target Name="_UpdatePackageId" BeforeTargets="$(PackDependsOn);InitializeSourceControlInformation" >
<PropertyGroup>
<PackageId>$(_ProjectDefinedPackageId)</PackageId>
<PackageId Condition="'$(PackageId)' == ''">$(AssemblyName)</PackageId>
<PackageId Condition="'$(PackageId)' == ''">$(MSBuildProjectName)</PackageId>
</PropertyGroup>
</Target>

</Project>
13 changes: 2 additions & 11 deletions src/Microsoft.Build.StandardCI/Microsoft.Build.StandardCI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,11 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<IsPackable>true</IsPackable>
<SuppressFinalPackageVersion>true</SuppressFinalPackageVersion>
<PackageDescription>Standard CI targets.</PackageDescription>
<PackageTags>Standard CI msbuild targets</PackageTags>
<DevelopmentDependency>true</DevelopmentDependency>
<!-- This is a content only package. -->
<NoWarn>$(NoWarn);NU5128</NoWarn>
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
<IsBuildTaskProject>true</IsBuildTaskProject>
<PackTasks>false</PackTasks>
</PropertyGroup>

<ItemGroup>
<None Include="build\Microsoft.Build.StandardCI.props"
Pack="true"
PackagePath="build" />
</ItemGroup>

</Project>
10 changes: 0 additions & 10 deletions src/Microsoft.Build.StandardCI/Microsoft.Build.StandardCI.nuspec

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the License.txt file in the project root for more information. -->
<Project>
<Import Project="..\build\$(MSBuildThisFileName).props"/>
</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net472;$(NetCurrent)</TargetFrameworks>
<TargetFrameworks>$(NetToolCurrent);$(NetFrameworkToolCurrent)</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
14 changes: 4 additions & 10 deletions src/Microsoft.Build.Tasks.Git/Microsoft.Build.Tasks.Git.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472;$(NetMinimum);$(NetCurrent)</TargetFrameworks>
<AutoGenerateAssemblyVersion>true</AutoGenerateAssemblyVersion>

<!-- NuGet: Using an explicit nuspec file to customize TFM directory -->
<IsPackable>true</IsPackable>
<NuspecFile>$(MSBuildProjectName).nuspec</NuspecFile>
<NuspecBasePath>$(OutputPath)</NuspecBasePath>

<PropertyGroup>
<TargetFrameworks>$(NetToolMinimum);$(NetFrameworkToolCurrent)</TargetFrameworks>
<PackageDescription>MSBuild tasks providing git repository information.</PackageDescription>
<PackageTags>MSBuild Tasks source control git</PackageTags>
<DevelopmentDependency>true</DevelopmentDependency>
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
<IsBuildTaskProject>true</IsBuildTaskProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Build" Version="$(MicrosoftBuildVersion)" />
Expand All @@ -25,4 +18,5 @@
<InternalsVisibleTo Include="Microsoft.Build.Tasks.Git.UnitTests" />
<InternalsVisibleTo Include="Microsoft.SourceLink.Git.IntegrationTests" />
</ItemGroup>

</Project>
15 changes: 0 additions & 15 deletions src/Microsoft.Build.Tasks.Git/Microsoft.Build.Tasks.Git.nuspec

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the License.txt file in the project root for more information. -->
<Project>
<PropertyGroup>
<MicrosoftBuildTasksGitAssemblyFile Condition="'$(MSBuildRuntimeType)' != 'Core'">$(MSBuildThisFileDirectory)..\tools\net472\Microsoft.Build.Tasks.Git.dll</MicrosoftBuildTasksGitAssemblyFile>
<MicrosoftBuildTasksGitAssemblyFile Condition="'$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)..\tools\core\Microsoft.Build.Tasks.Git.dll</MicrosoftBuildTasksGitAssemblyFile>
<MicrosoftBuildTasksGitAssemblyFile Condition="'$(MSBuildRuntimeType)' != 'Core'">$(MSBuildThisFileDirectory)..\tools\netframework\Microsoft.Build.Tasks.Git.dll</MicrosoftBuildTasksGitAssemblyFile>
<MicrosoftBuildTasksGitAssemblyFile Condition="'$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)..\tools\net\Microsoft.Build.Tasks.Git.dll</MicrosoftBuildTasksGitAssemblyFile>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the License.txt file in the project root for more information. -->
<Project>
<Import Project="..\build\$(MSBuildThisFileName).props"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import

Why do we need buildTransitive? Seems like a project that depends on a project that has Source Link may or may not opt-into having Source Link. Either way it should work as there is no cross-project dependency on source link.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buildTransitive is necessary so when a package references Microsoft.Build.Tasks.Git.nupkg, the end consumer then receives the msbuild props and targets files from it transitively. That's necessary when using NuGet's Pack task as it emits a slightly different nuspec in regards to IncludeAssets as the current ones.

NuGet/Home#6091 has all the details.

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the License.txt file in the project root for more information. -->
<Project>
<Import Project="..\build\$(MSBuildThisFileName).targets"/>
</Project>
14 changes: 4 additions & 10 deletions src/Microsoft.Build.Tasks.Tfvc/Microsoft.Build.Tasks.Tfvc.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<AutoGenerateAssemblyVersion>true</AutoGenerateAssemblyVersion>
<TargetFramework>$(NetFrameworkToolCurrent)</TargetFramework>
<SuppressFinalPackageVersion>true</SuppressFinalPackageVersion>

<!-- NuGet: Using an explicit nuspec file to customize TFM directory -->
<IsPackable>true</IsPackable>
<NuspecFile>$(MSBuildProjectName).nuspec</NuspecFile>
<NuspecBasePath>$(OutputPath)</NuspecBasePath>

<PackageDescription>MSBuild tasks providing TFVC repository information.</PackageDescription>
<PackageTags>MSBuild Tasks TFVC source link</PackageTags>
<DevelopmentDependency>true</DevelopmentDependency>
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
<IsBuildTaskProject>true</IsBuildTaskProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Build" Version="$(MicrosoftBuildVersion)" />
Expand All @@ -22,4 +15,5 @@
<ItemGroup>
<Compile Include="..\Common\Utilities\*.cs" Link="Common\%(FileName).cs" />
</ItemGroup>

</Project>
21 changes: 0 additions & 21 deletions src/Microsoft.Build.Tasks.Tfvc/Microsoft.Build.Tasks.Tfvc.nuspec

This file was deleted.