Skip to content

Commit 25cdd7a

Browse files
authored
Use PackageDownload in torn builds (#41951)
1 parent a1f16b8 commit 25cdd7a

File tree

6 files changed

+84
-54
lines changed

6 files changed

+84
-54
lines changed

eng/Publishing.props

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,6 @@
8888
</ItemGroup>
8989
</Target>
9090

91-
<!-- Similarly to FSharp above, Roslyn needs to publish its Framework.Toolset package alongside SDK
92-
so it can be picked up in BuildWithNetFrameworkHostedCompiler scenarios. -->
93-
<PropertyGroup>
94-
<PublishDependsOnTargets>$(PublishDependsOnTargets);_ResolvePublishRoslynNuGetPackages</PublishDependsOnTargets>
95-
</PropertyGroup>
96-
97-
<Target Name="_ResolvePublishRoslynNuGetPackages" Condition="'$(EnableDefaultArtifacts)' == 'true'">
98-
<ItemGroup>
99-
<RoslynPackagesToPush Include="$(NuGetPackageRoot)\Microsoft.Net.Compilers.Toolset.Framework\$(MicrosoftNetCompilersToolsetFrameworkPackageVersion)\*.nupkg" />
100-
<ItemsToPushToBlobFeed Include="@(RoslynPackagesToPush)" IsShipping="true" />
101-
</ItemGroup>
102-
</Target>
103-
10491
<!-- We use a separate target to publish this to blob storage so that we can push this to a relative path inside the blob storage. -->
10592
<Target Name="PublishToolsetAssets" DependsOnTargets="ReadToolsetVersion" BeforeTargets="Publish" Condition="'$(EnableDefaultArtifacts)' == 'true'">
10693
<ItemGroup>

sdk.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.WebTools.AspireSe
509509
EndProject
510510
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Microsoft.WebTools.AspireService", "src\BuiltInTools\AspireService\Microsoft.WebTools.AspireService.shproj", "{94C8526E-DCC2-442F-9868-3DD0BA2688BE}"
511511
EndProject
512+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Net.Sdk.Compilers.Toolset", "src\Microsoft.Net.Sdk.Compilers.Toolset\Microsoft.Net.Sdk.Compilers.Toolset.csproj", "{FA579C03-2EB4-4D47-88EE-BFF339E96FAF}"
513+
EndProject
512514
Global
513515
GlobalSection(SolutionConfigurationPlatforms) = preSolution
514516
Debug|Any CPU = Debug|Any CPU
@@ -971,6 +973,10 @@ Global
971973
{19014C60-F87C-4CC7-AC0F-C41B6126EBCE}.Debug|Any CPU.Build.0 = Debug|Any CPU
972974
{19014C60-F87C-4CC7-AC0F-C41B6126EBCE}.Release|Any CPU.ActiveCfg = Release|Any CPU
973975
{19014C60-F87C-4CC7-AC0F-C41B6126EBCE}.Release|Any CPU.Build.0 = Release|Any CPU
976+
{FA579C03-2EB4-4D47-88EE-BFF339E96FAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
977+
{FA579C03-2EB4-4D47-88EE-BFF339E96FAF}.Debug|Any CPU.Build.0 = Debug|Any CPU
978+
{FA579C03-2EB4-4D47-88EE-BFF339E96FAF}.Release|Any CPU.ActiveCfg = Release|Any CPU
979+
{FA579C03-2EB4-4D47-88EE-BFF339E96FAF}.Release|Any CPU.Build.0 = Release|Any CPU
974980
EndGlobalSection
975981
GlobalSection(SolutionProperties) = preSolution
976982
HideSolutionNode = FALSE
@@ -1150,6 +1156,7 @@ Global
11501156
{149E3D40-8115-4965-9305-5A1ADBF04899} = {580D1AE7-AA8F-4912-8B76-105594E00B3B}
11511157
{19014C60-F87C-4CC7-AC0F-C41B6126EBCE} = {71A9F549-0EB6-41F9-BC16-4A6C5007FC91}
11521158
{94C8526E-DCC2-442F-9868-3DD0BA2688BE} = {71A9F549-0EB6-41F9-BC16-4A6C5007FC91}
1159+
{FA579C03-2EB4-4D47-88EE-BFF339E96FAF} = {22AB674F-ED91-4FBC-BFEE-8A1E82F9F05E}
11531160
EndGlobalSection
11541161
GlobalSection(ExtensibilityGlobals) = postSolution
11551162
SolutionGuid = {FB8F26CE-4DE6-433F-B32A-79183020BBD6}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>$(SdkTargetFramework)</TargetFramework>
5+
<Description>Transport package for Microsoft.Net.Compilers.Toolset.Framework assemblies. For internal use only.</Description>
6+
<IsPackable>true</IsPackable>
7+
<IncludeBuildOutput>false</IncludeBuildOutput>
8+
<NoPackageAnalysis>true</NoPackageAnalysis>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Microsoft.Net.Compilers.Toolset.Framework" ExcludeAssets="All" GeneratePathProperty="true" Condition="'$(DotNetBuildSourceOnly)' != 'true'" />
13+
<Content Include="$(PkgMicrosoft_Net_Compilers_Toolset_Framework)\tasks\net472\**\*" PackagePath="%(RecursiveDir)" />
14+
</ItemGroup>
15+
16+
</Project>

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -220,24 +220,32 @@ Copyright (c) .NET Foundation. All rights reserved.
220220
</RebuildDependsOn>
221221
</PropertyGroup>
222222

223-
<Target Name="_AddMicrosoftNetCompilerToolsetFrameworkPackage" Condition="'$(MSBuildRuntimeType)' == 'Full'" BeforeTargets="CollectPackageReferences">
223+
<PropertyGroup Condition="'$(MSBuildRuntimeType)' == 'Full'">
224+
<!-- Automatically opt users into using the toolset package if they are running an MSBuild other than what this SDK was built against.
225+
This is to reduce 'tearing'/dependency mismatch, but as always users can override this behavior by disabling the hosted compiler flag. -->
226+
<BuildWithNetFrameworkHostedCompiler Condition="'$(BuildWithNetFrameworkHostedCompiler)' == '' and '$(_IsDisjointMSBuildVersion)' == 'true'">true</BuildWithNetFrameworkHostedCompiler>
227+
</PropertyGroup>
224228

225-
<!-- Users should not be setting Microsoft.Net.Compilers.Toolset.Framework directly.
226-
If they do, and they also set BuildWithNetFrameworkHostedCompiler, we will have
227-
a duplicate PackageReference. This makes it more explicit that that is not supported. -->
228-
<NETSdkWarning ResourceName="CannotDirectlyReferenceMicrosoftNetCompilersToolsetFramework"
229-
Condition="'@(PackageReference->AnyHaveMetadataValue('Identity', 'Microsoft.Net.Compilers.Toolset.Framework'))' == 'true'" />
229+
<PropertyGroup Condition="'$(BuildWithNetFrameworkHostedCompiler)' == 'true' and '$(OS)' == 'Windows_NT'">
230+
<RoslynTargetsPath>$(NuGetPackageRoot)\microsoft.net.sdk.compilers.toolset\$(NETCoreSdkVersion)</RoslynTargetsPath>
231+
<_NeedToDownloadMicrosoftNetSdkCompilersToolsetPackage>true</_NeedToDownloadMicrosoftNetSdkCompilersToolsetPackage>
232+
</PropertyGroup>
230233

231-
<PropertyGroup>
232-
<!-- Automatically opt users into using the toolset package if they are running an MSBuild other than what this SDK was built against.
233-
This is to reduce 'tearing'/depdendency mismatch, but as always users can override this behavior by disabling the hosted compiler flag. -->
234-
<BuildWithNetFrameworkHostedCompiler Condition="'$(BuildWithNetFrameworkHostedCompiler)' == '' and '$(_IsDisjointMSBuildVersion)' == 'true'">true</BuildWithNetFrameworkHostedCompiler>
235-
</PropertyGroup>
234+
<!-- NOTE: Keep in sync with https://github.com/dotnet/msbuild/blob/main/src/Tasks/Microsoft.Common.tasks -->
235+
<UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.CopyRefAssembly" AssemblyFile="$(RoslynTargetsPath)\Microsoft.Build.Tasks.CodeAnalysis.dll" />
236+
<UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.Csc" AssemblyFile="$(RoslynTargetsPath)\Microsoft.Build.Tasks.CodeAnalysis.dll" />
237+
<UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.Vbc" AssemblyFile="$(RoslynTargetsPath)\Microsoft.Build.Tasks.CodeAnalysis.dll" />
236238

237-
<ItemGroup Condition="'$(BuildWithNetFrameworkHostedCompiler)' == 'true' and '$(OS)' == 'Windows_NT' ">
238-
<PackageReference Include="Microsoft.Net.Compilers.Toolset.Framework" PrivateAssets="all" Version="$(_NetFrameworkHostedCompilersVersion)" IsImplicitlyDefined="true" />
239-
</ItemGroup>
239+
<ItemGroup Condition="'$(_NeedToDownloadMicrosoftNetSdkCompilersToolsetPackage)' == 'true'">
240+
<PackageDownload Include="Microsoft.Net.Sdk.Compilers.Toolset" Version="[$(NETCoreSdkVersion)]" />
241+
</ItemGroup>
240242

243+
<Target Name="_CheckMicrosoftNetSdkCompilersToolsetPackageReference" Condition="'$(MSBuildRuntimeType)' == 'Full'" BeforeTargets="CollectPackageReferences">
244+
<!-- Users should not be setting Microsoft.Net.Compilers.Toolset.Framework directly.
245+
If they do, and BuildWithNetFrameworkHostedCompiler is also set, the former will override the latter.
246+
This makes it more explicit that that is not supported. -->
247+
<NETSdkWarning ResourceName="CannotDirectlyReferenceMicrosoftNetCompilersToolsetFramework"
248+
Condition="'@(PackageReference->AnyHaveMetadataValue('Identity', 'Microsoft.Net.Compilers.Toolset.Framework'))' == 'true'" />
241249
</Target>
242250

243251
<!-- TODO: this target should not check GeneratePackageOnBuild.

test/Microsoft.NET.Restore.Tests/GivenThatWeWantToUseFrameworkRoslyn.cs

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public GivenThatWeWantToUseFrameworkRoslyn(ITestOutputHelper log) : base(log)
1010
}
1111

1212
[FullMSBuildOnlyFact]
13-
public void It_restores_Microsoft_Net_Compilers_Toolset_Framework_when_requested()
13+
public void It_downloads_Microsoft_Net_Compilers_Toolset_Framework_when_requested()
1414
{
1515
const string testProjectName = "NetCoreApp";
1616
var project = new TestProject
@@ -24,21 +24,28 @@ public void It_restores_Microsoft_Net_Compilers_Toolset_Framework_when_requested
2424
var testAsset = _testAssetsManager
2525
.CreateTestProject(project);
2626

27-
string projectAssetsJsonPath = Path.Combine(
28-
testAsset.Path,
29-
project.Name,
30-
"obj",
31-
"project.assets.json");
27+
NuGetConfigWriter.Write(testAsset.Path, TestContext.Current.TestPackages);
3228

33-
var restoreCommand =
34-
testAsset.GetRestoreCommand(Log, relativePath: testProjectName);
35-
restoreCommand.Execute().Should().Pass();
29+
var customPackagesDir = Path.Combine(testAsset.Path, "nuget-packages");
30+
31+
testAsset.GetRestoreCommand(Log, relativePath: testProjectName)
32+
.WithEnvironmentVariable("NUGET_PACKAGES", customPackagesDir)
33+
.Execute().Should().Pass();
34+
35+
var toolsetPackageDir = Path.Combine(customPackagesDir, "microsoft.net.sdk.compilers.toolset");
3636

37-
Assert.Contains("Microsoft.Net.Compilers.Toolset.Framework", File.ReadAllText(projectAssetsJsonPath));
37+
Assert.True(Directory.Exists(toolsetPackageDir));
38+
39+
var toolsetPackageVersion = Directory.EnumerateDirectories(toolsetPackageDir).Should().ContainSingle().Subject;
40+
41+
new BuildCommand(testAsset)
42+
.WithEnvironmentVariable("NUGET_PACKAGES", customPackagesDir)
43+
.Execute().Should().Pass().And
44+
.HaveStdOutContaining(Path.Combine(toolsetPackageDir, toolsetPackageVersion, "csc.exe") + " /noconfig");
3845
}
3946

4047
[FullMSBuildOnlyFact]
41-
public void It_restores_Microsoft_Net_Compilers_Toolset_Framework_when_MSBuild_is_torn()
48+
public void It_downloads_Microsoft_Net_Compilers_Toolset_Framework_when_MSBuild_is_torn()
4249
{
4350
const string testProjectName = "NetCoreApp";
4451
var project = new TestProject
@@ -53,24 +60,24 @@ public void It_restores_Microsoft_Net_Compilers_Toolset_Framework_when_MSBuild_i
5360
var testAsset = _testAssetsManager
5461
.CreateTestProject(project);
5562

56-
string projectAssetsJsonPath = Path.Combine(
57-
testAsset.Path,
58-
project.Name,
59-
"obj",
60-
"project.assets.json");
63+
NuGetConfigWriter.Write(testAsset.Path, TestContext.Current.TestPackages);
6164

62-
var restoreCommand =
63-
testAsset.GetRestoreCommand(Log, relativePath: testProjectName);
64-
restoreCommand.Execute().Should().Pass();
65+
var customPackagesDir = Path.Combine(testAsset.Path, "nuget-packages");
6566

66-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
67-
{
68-
Assert.Contains("Microsoft.Net.Compilers.Toolset.Framework", File.ReadAllText(projectAssetsJsonPath));
69-
}
70-
else
71-
{
72-
Assert.DoesNotContain("Microsoft.Net.Compilers.Toolset.Framework", File.ReadAllText(projectAssetsJsonPath));
73-
}
67+
testAsset.GetRestoreCommand(Log, relativePath: testProjectName)
68+
.WithEnvironmentVariable("NUGET_PACKAGES", customPackagesDir)
69+
.Execute().Should().Pass();
70+
71+
var toolsetPackageDir = Path.Combine(customPackagesDir, "microsoft.net.sdk.compilers.toolset");
72+
73+
Assert.True(Directory.Exists(toolsetPackageDir));
74+
75+
var toolsetPackageVersion = Directory.EnumerateDirectories(toolsetPackageDir).Should().ContainSingle().Subject;
76+
77+
new BuildCommand(testAsset)
78+
.WithEnvironmentVariable("NUGET_PACKAGES", customPackagesDir)
79+
.Execute().Should().Pass().And
80+
.HaveStdOutContaining(Path.Combine(toolsetPackageDir, toolsetPackageVersion, "csc.exe") + " /noconfig");
7481
}
7582

7683
[FullMSBuildOnlyFact]

test/Microsoft.NET.TestFramework/BuildTestPackages.targets

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@
154154
<Version>1.0.0</Version>
155155
<Clean>True</Clean>
156156
</BaseTestPackageProject>
157+
<BaseTestPackageProject Include="src/Microsoft.Net.Sdk.Compilers.Toolset">
158+
<Name>Microsoft.Net.Sdk.Compilers.Toolset</Name>
159+
<ProjectName>Microsoft.Net.Sdk.Compilers.Toolset.csproj</ProjectName>
160+
<Version>$(Version)</Version>
161+
</BaseTestPackageProject>
157162

158163
<BaseTestPackageProject>
159164
<NuPkgName Condition=" '%(NuPkgName)' == '' ">%(Name)</NuPkgName>

0 commit comments

Comments
 (0)