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

Flow NuGetPackageRoot out of Tools.proj restore #14879

Open
wants to merge 6 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 32 additions & 18 deletions src/Microsoft.DotNet.Arcade.Sdk/tools/Build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -133,29 +133,51 @@
<_CommonProps Include="VCTargetsPath=$([MSBuild]::ValueOrDefault('$(VCTargetsPath)', '$([MSBuild]::GetVsInstallRoot())\Common7\IDE\VC\VCTargets\'))" Condition="'$(MSBuildRuntimeType)' != 'Core'"/>
</ItemGroup>

<ItemGroup Condition="'$(Restore)' == 'true'">
<_RestoreToolsProps Include="@(_CommonProps)"/>
<_RestoreToolsProps Include="BaseIntermediateOutputPath=$(ArtifactsToolsetDir)Common"/>
<_RestoreToolsProps Include="ExcludeRestorePackageImports=true"/>
Copy link
Member

Choose a reason for hiding this comment

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

📝 Setting this property forces Tools.proj.nuget.g.props to not be included. This is fine on the restore path, but we need to avoid it when invoking the ReturnNuGetPackageRoot target.

<_RestoreToolsProps Include="_NuGetRestoreTargets=$(_NuGetRestoreTargets)"/>
<ItemGroup>
<_CommonToolsProps Include="@(_CommonProps)"/>
<_CommonToolsProps Include="BaseIntermediateOutputPath=$(ArtifactsToolsetDir)Common"/>
<_CommonToolsProps Include="_NuGetRestoreTargets=$(_NuGetRestoreTargets)"/>

<!-- Used in the SDK (Tools.proj) to control whether Build.Tasks.Feed will be restored or not. -->
<_RestoreToolsProps Include="Publish=$(Publish)"/>
<_CommonToolsProps Include="Publish=$(Publish)"/>

<!-- Used in the SDK (Tools.proj) to control whether SymbolUploader.Build.Task will be restored or not. -->
<_RestoreToolsProps Include="PublishToSymbolServer=$(PublishToSymbolServer)"/>
<_CommonToolsProps Include="PublishToSymbolServer=$(PublishToSymbolServer)"/>

<!-- Forward this property because we can't assume it will be available globally. -->
<_RestoreToolsProps Include="DotNetPublishUsingPipelines=$(DotNetPublishUsingPipelines)"/>
<_CommonToolsProps Include="DotNetPublishUsingPipelines=$(DotNetPublishUsingPipelines)"/>
</ItemGroup>

<!--
Builds from the 'internal' project, and only those, can download the .net Runtime
from a private location.
-->
<ItemGroup Condition="'$(SYSTEM_TEAMPROJECT)' == 'internal'">
<_RestoreToolsProps Include="DotNetRuntimeSourceFeed=$(DotNetRuntimeSourceFeed)"/>
<_RestoreToolsProps Include="DotNetRuntimeSourceFeedKey=$(DotNetRuntimeSourceFeedKey)"/>
<_CommonToolsProps Include="DotNetRuntimeSourceFeed=$(DotNetRuntimeSourceFeed)"/>
<_CommonToolsProps Include="DotNetRuntimeSourceFeedKey=$(DotNetRuntimeSourceFeedKey)"/>
</ItemGroup>

<ItemGroup>
<_RestoreToolsProps Include="@(_CommonToolsProps)"/>
<_RestoreToolsProps Include="ExcludeRestorePackageImports=true"/>
</ItemGroup>

<!--
Restore built-in tools if requested, and extract information from the NuGet restore output.
-->
<MSBuild Projects="Tools.proj"
Targets="Restore"
Properties="@(_RestoreToolsProps);_NETCORE_ENGINEERING_TELEMETRY=Restore"
Condition="'$(Restore)' == 'true'"/>

<MSBuild Projects="Tools.proj"
Targets="ReturnNuGetPackageRoot"
Properties="@(_CommonToolsProps);_NETCORE_ENGINEERING_TELEMETRY=ReturnNuGetPackageRoot">
<Output TaskParameter="TargetOutputs" ItemName="_RestoreToolsOutput" />
</MSBuild>

<ItemGroup>
<_CommonProps Include="@(_RestoreToolsOutput->'NuGetPackageRoot=%(Identity)')"/>
</ItemGroup>

<ItemGroup>
Expand All @@ -177,14 +199,6 @@
<_SolutionBuildProps Include="__ImportPackTargets=true" Condition="'$(Pack)' == 'true'" />
</ItemGroup>

<!--
Restore built-in tools.
-->
<MSBuild Projects="Tools.proj"
Targets="Restore"
Properties="@(_RestoreToolsProps);_NETCORE_ENGINEERING_TELEMETRY=Restore"
Condition="'$(Restore)' == 'true'"/>

<!--
Restore solutions and projects.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- Sourced from NuGet package Microsoft.Build.NoTargets -->
<Project>
<!-- Disables the _CopyFilesMarkedCopyLocal target by overriding it -->
<Target Name="_CopyFilesMarkedCopyLocal" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (c) Microsoft Corporation. All rights reserved.

Licensed under the MIT license.
-->
<!-- Sourced from NuGet package Microsoft.Build.NoTargets -->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<UsingMicrosoftNoTargetsSdk>true</UsingMicrosoftNoTargetsSdk>
<MSBuildAllProjects Condition="'$(MSBuildToolsVersion)' != 'Current'">$(MSBuildAllProjects);$(MsBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>

<PropertyGroup>
<!-- Copy logic to know if managed targets got imported: https://github.com/dotnet/sdk/blob/49002c14cf91ecd08e79d6184dbd4716c005b509/src/Tasks/Microsoft.NET.Build.Tasks/sdk/Sdk.targets#L25-L27 -->
<ManagedLanguageTargetsGotImported Condition="'$(MSBuildProjectExtension)' == '.csproj'">true</ManagedLanguageTargetsGotImported>
<ManagedLanguageTargetsGotImported Condition="'$(MSBuildProjectExtension)' == '.vbproj'">true</ManagedLanguageTargetsGotImported>
<ManagedLanguageTargetsGotImported Condition="'$(MSBuildProjectExtension)' == '.fsproj'">true</ManagedLanguageTargetsGotImported>
</PropertyGroup>

<Import Project="$(CustomBeforeNoTargetsProps)" Condition=" '$(CustomBeforeNoTargetsProps)' != '' And Exists('$(CustomBeforeNoTargetsProps)') " />

<PropertyGroup>
<!-- Disable default Compile and EmbeddedResource items for NoTargets projects -->
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems>

<!--
NuGet should always restore Traversal projects with "PackageReference" style restore. Setting this property will cause the right thing to happen even if there aren't any PackageReference items in the project.
-->
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>

<!-- Targeting packs shouldn't be referenced as traversal projects don't compile. -->
<DisableImplicitFrameworkReferences Condition="'$(DisableImplicitFrameworkReferences)' == ''">true</DisableImplicitFrameworkReferences>

<!-- Disable publish actions -->
<CopyBuildOutputToPublishDirectory Condition="'$(CopyBuildOutputToPublishDirectory)' == ''">false</CopyBuildOutputToPublishDirectory>
<CopyOutputSymbolsToPublishDirectory Condition="'$(CopyOutputSymbolsToPublishDirectory)' == ''">false</CopyOutputSymbolsToPublishDirectory>

<!-- Don't generate a deps file -->
<GenerateDependencyFile Condition="'$(GenerateDependencyFile)' == ''">false</GenerateDependencyFile>

<!-- Don't generate assembly info -->
<GenerateAssemblyInfo Condition="'$(GenerateAssemblyInfo)' == ''">false</GenerateAssemblyInfo>

<!-- Don't generate editor config file -->
<GenerateMSBuildEditorConfigFile Condition="'$(GenerateMSBuildEditorConfigFile)' == ''">false</GenerateMSBuildEditorConfigFile>

<!-- Don't log the high priority message mentioning this project's name (or copy the product we didn't build). -->
<SkipCopyBuildProduct Condition="'$(SkipCopyBuildProduct)' == ''">true</SkipCopyBuildProduct>

<!-- Don't automatically reference assembly packages since NoTargets don't need reference assemblies -->
<AutomaticallyUseReferenceAssemblyPackages Condition="'$(AutomaticallyUseReferenceAssemblyPackages)' == ''">false</AutomaticallyUseReferenceAssemblyPackages>
<NoCompilerStandardLib Condition="'$(NoCompilerStandardLib)' == ''">false</NoCompilerStandardLib>
<NoStdLib Condition="'$(NoStdLib)' == ''">true</NoStdLib>

<!-- Disable Visual Studio's Fast Up-to-date Check and rely on MSBuild to determine -->
<DisableFastUpToDateCheck Condition="'$(DisableFastUpToDateCheck)' == ''">true</DisableFastUpToDateCheck>
</PropertyGroup>

<ItemDefinitionGroup Condition=" '$(NoTargetsDoNotReferenceOutputAssemblies)' != 'false' ">
<ProjectReference>
<!--
Setting ReferenceOutputAssembly skips target framework cross-project validation in NuGet. Since NoTargets projects don't define runtime
constraints like a target framework, there's no point in checking the compatibilty of project references.
-->
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<SkipGetTargetFrameworkProperties>true</SkipGetTargetFrameworkProperties>
</ProjectReference>
</ItemDefinitionGroup>

<Target Name="CreateManifestResourceNames" />

<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" Condition=" '$(MicrosoftCommonPropsHasBeenImported)' != 'true' "/>

<Import Project="$(CustomAfterNoTargetsProps)" Condition=" '$(CustomAfterNoTargetsProps)' != '' And Exists('$(CustomAfterNoTargetsProps)') " />

<!-- For CPS/VS support. Importing in .props allows any subsequent targets to redefine this if needed -->
<Target Name="CompileDesignTime" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (c) Microsoft Corporation. All rights reserved.

Licensed under the MIT license.
-->
<!-- Sourced from NuGet package Microsoft.Build.NoTargets -->
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<!--
Set LanguageTargets to Microsoft.Common.targets for any project that the SDK won't (.proj, .noproj, etc)
https://github.com/dotnet/sdk/blob/50ddfbb91be94d068514e8f4b0ce1052156364a0/src/Tasks/Microsoft.NET.Build.Tasks/sdk/Sdk.targets#L28

We can't default LanguageTargets it is set in the SDK and immediately imported. So we can only default
it if we know the SDK won't. Projects probably won't load in Visual Studio but will build from the
command-line just fine.
-->
<PropertyGroup>
<LanguageTargets Condition=" '$(LanguageTargets)' == '' And '$(MSBuildProjectExtension)' != '.csproj' And '$(MSBuildProjectExtension)' != '.vbproj' And '$(MSBuildProjectExtension)' != '.fsproj' ">$(MSBuildToolsPath)\Microsoft.Common.targets</LanguageTargets>
<MSBuildAllProjects Condition="'$(MSBuildToolsVersion)' != 'Current'">$(MSBuildAllProjects);$(MsBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>

<Import Project="$(CustomBeforeNoTargets)" Condition="'$(CustomBeforeNoTargets)' != '' and Exists('$(CustomBeforeNoTargets)')" />

<PropertyGroup>
<!-- Don't include build output in a package since NoTargets projects don't emit an assembly. -->
<IncludeBuildOutput Condition="'$(IncludeBuildOutput)' == ''">false</IncludeBuildOutput>

<!-- For CPS/VS support. See https://github.com/dotnet/project-system/blob/master/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/DesignTimeTargets/Microsoft.Managed.DesignTime.targets#L60 -->
<CustomBeforeMicrosoftCommonTargets Condition="'$(ManagedLanguageTargetsGotImported)' == '' And Exists('$(MSBuildExtensionsPath)\Microsoft\VisualStudio\Managed\Microsoft.Managed.DesignTime.targets')">$(CustomBeforeMicrosoftCommonTargets);$(MSBuildExtensionsPath)\Microsoft\VisualStudio\Managed\Microsoft.Managed.DesignTime.targets</CustomBeforeMicrosoftCommonTargets>
</PropertyGroup>

<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" Condition=" '$(CommonTargetsPath)' == '' " />

<PropertyGroup>
<!-- This property must be overridden to remove a few targets that compile assemblies -->
<CoreBuildDependsOn>
BuildOnlySettings;
PrepareForBuild;
PreBuildEvent;
ResolveReferences;
Compile;
GetTargetPath;
PrepareForRun;
IncrementalClean;
PostBuildEvent
</CoreBuildDependsOn>

<!-- Disable symbol generation -->
<DebugType>None</DebugType>
<DebugSymbols>false</DebugSymbols>

<!-- Don't emit a reference assembly -->
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
</PropertyGroup>

<!-- Clear output group items which are read by the IDE and NuGet. -->
<ItemGroup>
<BuiltProjectOutputGroupKeyOutput Remove="@(BuiltProjectOutputGroupKeyOutput)" />
<DebugSymbolsProjectOutputGroupOutput Remove="@(DebugSymbolsProjectOutputGroupOutput)" />
<IntermediateAssembly Remove="@(IntermediateAssembly)" />
<IntermediateRefAssembly Remove="@(IntermediateRefAssembly)" />
<Reference Remove="mscorlib" />
</ItemGroup>

<!--
The CopyFilesToOutputDirectory target is hard coded to depend on ComputeIntermediateSatelliteAssemblies. NoTargets projects do no generate resource assemblies
so the target is replaced with a no-op
-->
<Target Name="ComputeIntermediateSatelliteAssemblies" />

<!--
NoTargets projects do not build an assembly so dependent projects shouldn't get a path to the target. Override the GetTargetPath to do nothing.
-->
<Target Name="GetTargetPath" />

<!--
The GetTargetPathWithTargetPlatformMoniker target uses a BeforeTargets so the only way to disable it is to override it with an empty target.
-->
<Target Name="GetTargetPathWithTargetPlatformMoniker" />

<!--
The GetReferenceAssemblyPaths does not need to run since reference assemblies aren't needed.
-->
<Target Name="GetFrameworkPaths" DependsOnTargets="$(GetFrameworkPathsDependsOn)" />
<Target Name="GetReferenceAssemblyPaths" DependsOnTargets="$(GetReferenceAssemblyPathsDependsOn)" />

<Import Project="$(CustomAfterNoTargets)" Condition="'$(CustomAfterNoTargets)' != '' and Exists('$(CustomAfterNoTargets)')" />

<!--
Microsoft.Managed.Targets is imported by the managed language target files in MSBuild 16.0 and above, but most of the msbuild tasks are actually in Microsoft.Common.Currentversion.targets.
So import it when the managed targets do not get imported.
-->
<Import Project="$(MSBuildToolsPath)\Microsoft.Managed.targets" Condition="'$(MSBuildAssemblyVersion)' >= '16.0' And '$(ManagedLanguageTargetsGotImported)' != 'true'" />

<!-- Override stock CoreCompile target to do nothing but keep extensibility points -->
<Target Name="CoreCompile"
DependsOnTargets="$(CoreCompileDependsOn)">
<CallTarget Targets="$(TargetsTriggeredByCompilation)" Condition="'$(TargetsTriggeredByCompilation)' != ''" />
</Target>

<Target Name="_GenerateCompileInputs" />
<Target Name="_GenerateCompileDependencyCache" />

<!-- Disables the _CopyFilesMarkedCopyLocal target to not copy references when SkipCopyFilesMarkedCopyLocal is set to false. -->
<Import Project="Microsoft.Build.NoTargets.3.7.56.DisableCopyFilesMarkedCopyLocal.targets" Condition="'$(SkipCopyFilesMarkedCopyLocal)' == 'true'" />
</Project>
10 changes: 9 additions & 1 deletion src/Microsoft.DotNet.Arcade.Sdk/tools/Tools.proj
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. -->
<Project>

<Import Project="Microsoft.Build.NoTargets.3.7.56.Sdk.props"/>

<Import Project="BuildStep.props" />

<!-- Properties requires by NuGet.targets to restore PackageReferences -->
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<!-- Workaround changes from newer MSBuild requiring additional properties -->
<TargetFrameworkVersion Condition="'$(TargetFrameworkVersion)' == ''">5</TargetFrameworkVersion>
Copy link
Member

Choose a reason for hiding this comment

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

📝 This value was simply wrong, and after updating to use Microsoft.Build.Traversal it was resulting in build errors.

<TargetFrameworkVersion Condition="'$(TargetFrameworkVersion)' == ''">v4.7.2</TargetFrameworkVersion>
<TargetFrameworkIdentifier Condition="'$(TargetFrameworkIdentifier)' == ''">.NETFramework</TargetFrameworkIdentifier>
<TargetFrameworkMoniker Condition="'$(TargetFrameworkMoniker)' == ''">.NETFramework,Version=v4.7.2</TargetFrameworkMoniker>
<MSBuildProjectExtensionsPath>$(BaseIntermediateOutputPath)</MSBuildProjectExtensionsPath>
Expand Down Expand Up @@ -86,6 +88,10 @@
Condition="'$(Restore)' == 'true'"/>
</Target>

<Target Name="ReturnNuGetPackageRoot" Returns="$(NuGetPackageRoot)">
<Error Text="Unable to determine 'NuGetPackageRoot' prior to restore." Condition="'$(NuGetPackageRoot)' == ''" />
</Target>

<Import Project="SourceBuild/SourceBuildArcadeTools.targets" Condition="'$(ArcadeBuildFromSource)' == 'true' or
'$(DotNetBuildRepo)' == 'true' or
'$(SetUpSourceBuildIntermediateNupkgCache)' == 'true'" />
Expand All @@ -97,4 +103,6 @@

<Import Project="VisualStudio.AcquireOptimizationData.targets" Condition="'$(UsingToolVisualStudioIbcTraining)' == 'true'" />

<Import Project="Microsoft.Build.NoTargets.3.7.56.Sdk.targets"/>

</Project>
Loading