Skip to content

Commit

Permalink
Use csproj as pack input instead of nuspec
Browse files Browse the repository at this point in the history
Now that sourcelink is a native part of the .NET SDK, Arcade doesn't
bring sourcelink packages in anymore. Now that the cyclic package
dependency is avoided, these projects don't need to use nuspecs
anymore.

This removes custom infrastructure and allows better source build
controls.

I diffed the produced packages and the content in the .NETCoreApp
folder is identical (a deps.json file is added but that's
recommended by msbuild for build tasks these days). The .NET Framework
output is significantly different as it now includes all dependencies
that aren't supplied by the MSBuild inside Visual Studio.
  • Loading branch information
ViktorHofer committed Oct 27, 2023
1 parent ed56d42 commit 13aebe2
Show file tree
Hide file tree
Showing 51 changed files with 157 additions and 395 deletions.
94 changes: 94 additions & 0 deletions eng/BuildTask.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<Project>

<PropertyGroup>
<IncludeBuildOutput>false</IncludeBuildOutput>
<IsPackable>true</IsPackable>
<!-- Build Tasks should not include any dependencies -->
<SuppressDependenciesWhenPacking Condition="'$(SuppressDependenciesWhenPacking)' == ''">true</SuppressDependenciesWhenPacking>
<!-- Build Tasks should have this set per https://github.com/dotnet/arcade/blob/main/Documentation/CorePackages/Versioning.md#recommended-settings -->
<AutoGenerateAssemblyVersion>true</AutoGenerateAssemblyVersion>
<BuildTaskTargetFolder Condition="'$(BuildTaskTargetFolder)' == ''">tools</BuildTaskTargetFolder>
<PackTasks Condition="'$(PackTasks)' == ''">true</PackTasks>
<TargetsForTfmSpecificContentInPackage Condition="'$(PackTasks)' == 'true'">$(TargetsForTfmSpecificContentInPackage);_AddBuildOutputToPackageCore;_AddBuildOutputToPackageDesktop</TargetsForTfmSpecificContentInPackage>
<DevelopmentDependency>true</DevelopmentDependency>
</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>

<!-- Exclude 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>

<!-- Exclude assemblies that are already provided by the SDK, next to MSBuild. -->
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<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 -->
<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.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>
<ExcludeAssets Condition="'%(PackageReference.Publish)' == 'false'">runtime</ExcludeAssets>
</PackageReference>
</ItemGroup>

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

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

</Project>
11 changes: 4 additions & 7 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@
<GenerateResxSource>true</GenerateResxSource>

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

<!-- TODO: Remove when https://github.com/dotnet/arcade/pull/14165 is consumed. -->
<NetToolCurrent Condition="'$(NetToolCurrent)' == ''">net8.0</NetToolCurrent>
</PropertyGroup>

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

</Project>
25 changes: 0 additions & 25 deletions src/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,11 @@
<PackageReference Include="NETStandard.Library" Version="2.0.3" Condition="'$(TargetFrameworkIdentifier)' != '.NETStandard'" />
</ItemGroup>

<ItemGroup>
<NuspecProperty Include="DesktopTfm=net472"/>
<NuspecProperty Include="CoreTfm=$(NetCurrent)" Condition="'$(DotNetBuildFromSource)' == 'true'"/>
<NuspecProperty Include="CoreTfm=$(NetMinimum)" Condition="'$(DotNetBuildFromSource)' != '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>

<!--
Workaround for https://github.com/Microsoft/msbuild/issues/2527.
-->
<PropertyGroup>
<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>
11 changes: 1 addition & 10 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>
</PropertyGroup>

<ItemGroup>
<None Include="build\Microsoft.Build.StandardCI.props"
Pack="true"
PackagePath="build" />
</ItemGroup>
<Import Project="$(RepositoryEngineeringDir)BuildTask.targets" />

</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
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
Expand Down
13 changes: 3 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,8 @@
<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>

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

<Import Project="$(RepositoryEngineeringDir)BuildTask.targets" />
</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
Expand Up @@ -2,6 +2,6 @@
<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\net8.0\Microsoft.Build.Tasks.Git.dll</MicrosoftBuildTasksGitAssemblyFile>
</PropertyGroup>
</Project>
13 changes: 3 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,9 @@
<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>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Build" Version="$(MicrosoftBuildVersion)" />
Expand All @@ -24,4 +15,6 @@
<Compile Include="..\Common\PathUtilities.cs" Link="Common\PathUtilities.cs" />
<Compile Include="..\Common\UriUtilities.cs" Link="Common\UriUtilities.cs" />
</ItemGroup>

<Import Project="$(RepositoryEngineeringDir)BuildTask.targets" />
</Project>
21 changes: 0 additions & 21 deletions src/Microsoft.Build.Tasks.Tfvc/Microsoft.Build.Tasks.Tfvc.nuspec

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472;$(NetCurrent)</TargetFrameworks>
<TargetFrameworks>$(NetToolCurrent);$(NetFrameworkToolCurrent)</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SourceLink.AzureDevOpsServer.Git\Microsoft.SourceLink.AzureDevOpsServer.Git.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472;$(NetMinimum);$(NetCurrent)</TargetFrameworks>
<AutoGenerateAssemblyVersion>true</AutoGenerateAssemblyVersion>

<!-- Using an explicit nuspec file due to https://github.com/NuGet/Home/issues/6754 -->
<IsPackable>true</IsPackable>
<NuspecFile>$(MSBuildProjectName).nuspec</NuspecFile>
<NuspecBasePath>$(OutputPath)</NuspecBasePath>

<TargetFrameworks>$(NetToolCurrent);$(NetFrameworkToolCurrent)</TargetFrameworks>
<PackageDescription>Generates source link for Azure DevOps Server (formerly known as TFS) Git repositories.</PackageDescription>
<PackageTags>MSBuild Tasks Azure DepOps Server TFS Git source link</PackageTags>
<DevelopmentDependency>true</DevelopmentDependency>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Common\NullableAttributes.cs" Link="Common\NullableAttributes.cs" />
Expand All @@ -31,4 +23,6 @@
<ItemGroup>
<InternalsVisibleTo Include="Microsoft.SourceLink.AzureDevOpsServer.Git.UnitTests" />
</ItemGroup>

<Import Project="$(RepositoryEngineeringDir)BuildTask.targets" />
</Project>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<PropertyGroup>
<_SourceLinkAzureDevOpsServerGitAssemblyFile Condition="'$(MSBuildRuntimeType)' != 'Core'">$(MSBuildThisFileDirectory)..\tools\net472\Microsoft.SourceLink.AzureDevOpsServer.Git.dll</_SourceLinkAzureDevOpsServerGitAssemblyFile>
<_SourceLinkAzureDevOpsServerGitAssemblyFile Condition="'$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)..\tools\core\Microsoft.SourceLink.AzureDevOpsServer.Git.dll</_SourceLinkAzureDevOpsServerGitAssemblyFile>
<_SourceLinkAzureDevOpsServerGitAssemblyFile Condition="'$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)..\tools\net8.0\Microsoft.SourceLink.AzureDevOpsServer.Git.dll</_SourceLinkAzureDevOpsServerGitAssemblyFile>
</PropertyGroup>

<UsingTask TaskName="Microsoft.SourceLink.AzureDevOpsServer.Git.GetSourceLinkUrl" AssemblyFile="$(_SourceLinkAzureDevOpsServerGitAssemblyFile)"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472;$(NetCurrent)</TargetFrameworks>
<TargetFrameworks>$(NetToolCurrent);$(NetFrameworkToolCurrent)</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SourceLink.AzureRepos.Git\Microsoft.SourceLink.AzureRepos.Git.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472;$(NetMinimum);$(NetCurrent)</TargetFrameworks>
<AutoGenerateAssemblyVersion>true</AutoGenerateAssemblyVersion>

<!-- Using an explicit nuspec file due to https://github.com/NuGet/Home/issues/6754 -->
<IsPackable>true</IsPackable>
<NuspecFile>$(MSBuildProjectName).nuspec</NuspecFile>
<NuspecBasePath>$(OutputPath)</NuspecBasePath>

<TargetFrameworks>$(NetToolCurrent);$(NetFrameworkToolCurrent)</TargetFrameworks>
<PackageDescription>Generates source link for Azure Repos (formerly known as VSTS) Git repositories.</PackageDescription>
<PackageTags>MSBuild Tasks Azure DevOps Repos VSTS Git source link</PackageTags>
<DevelopmentDependency>true</DevelopmentDependency>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Common\NullableAttributes.cs" Link="Common\NullableAttributes.cs" />
Expand All @@ -31,4 +23,6 @@
<ItemGroup>
<InternalsVisibleTo Include="Microsoft.SourceLink.AzureRepos.Git.UnitTests" />
</ItemGroup>

<Import Project="$(RepositoryEngineeringDir)BuildTask.targets" />
</Project>

0 comments on commit 13aebe2

Please sign in to comment.