-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 PackageDownload in torn builds #41951
Changes from 5 commits
7570bfc
080bd3d
9e8feb3
13beb4d
23cf26a
f8fce72
3824f41
70bd6ed
b1840b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>$(SdkTargetFramework)</TargetFramework> | ||
<Description>Transport package for Microsoft.Net.Compilers.Toolset.Framework assemblies. For internal use only.</Description> | ||
<IsPackable>true</IsPackable> | ||
<IncludeBuildOutput>false</IncludeBuildOutput> | ||
<NoPackageAnalysis>true</NoPackageAnalysis> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Net.Compilers.Toolset.Framework" ExcludeAssets="All" GeneratePathProperty="true" Condition="'$(DotNetBuildSourceOnly)' != 'true'" /> | ||
<Content Include="$(PkgMicrosoft_Net_Compilers_Toolset_Framework)\tasks\net472\**\*" PackagePath="%(RecursiveDir)" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -220,24 +220,31 @@ Copyright (c) .NET Foundation. All rights reserved. | |
</RebuildDependsOn> | ||
</PropertyGroup> | ||
|
||
<Target Name="_AddMicrosoftNetCompilerToolsetFrameworkPackage" Condition="'$(MSBuildRuntimeType)' == 'Full'" BeforeTargets="CollectPackageReferences"> | ||
<PropertyGroup Condition="'$(MSBuildRuntimeType)' == 'Full'"> | ||
<!-- Automatically opt users into using the toolset package if they are running an MSBuild other than what this SDK was built against. | ||
This is to reduce 'tearing'/dependency mismatch, but as always users can override this behavior by disabling the hosted compiler flag. --> | ||
<BuildWithNetFrameworkHostedCompiler Condition="'$(BuildWithNetFrameworkHostedCompiler)' == '' and '$(_IsDisjointMSBuildVersion)' == 'true'">true</BuildWithNetFrameworkHostedCompiler> | ||
</PropertyGroup> | ||
|
||
<!-- Users should not be setting Microsoft.Net.Compilers.Toolset.Framework directly. | ||
If they do, and they also set BuildWithNetFrameworkHostedCompiler, we will have | ||
a duplicate PackageReference. This makes it more explicit that that is not supported. --> | ||
<NETSdkWarning ResourceName="CannotDirectlyReferenceMicrosoftNetCompilersToolsetFramework" | ||
Condition="'@(PackageReference->AnyHaveMetadataValue('Identity', 'Microsoft.Net.Compilers.Toolset.Framework'))' == 'true'" /> | ||
<PropertyGroup Condition="'$(BuildWithNetFrameworkHostedCompiler)' == 'true' and '$(OS)' == 'Windows_NT'"> | ||
<RoslynTargetsPath>$(NuGetPackageRoot)\microsoft.net.sdk.compilers.toolset\$(NETCoreSdkVersion)</RoslynTargetsPath> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think for Also, what happens during the restore phase when the package hasn't been downloaded yet. Is it OK for restore if this points to a non-existent path? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think the property is not available for PackageDownload: NuGet/Home#8476 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think yes, the compiler shouldn't be used during or before restore, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Looks like you were right, that is a problem in Visual Studio: #42238 |
||
<_NeedToDownloadMicrosoftNetSdkCompilersToolsetPackage>true</_NeedToDownloadMicrosoftNetSdkCompilersToolsetPackage> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<!-- Automatically opt users into using the toolset package if they are running an MSBuild other than what this SDK was built against. | ||
This is to reduce 'tearing'/depdendency mismatch, but as always users can override this behavior by disabling the hosted compiler flag. --> | ||
<BuildWithNetFrameworkHostedCompiler Condition="'$(BuildWithNetFrameworkHostedCompiler)' == '' and '$(_IsDisjointMSBuildVersion)' == 'true'">true</BuildWithNetFrameworkHostedCompiler> | ||
</PropertyGroup> | ||
<UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.CopyRefAssembly" AssemblyFile="$(RoslynTargetsPath)\Microsoft.Build.Tasks.CodeAnalysis.dll" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rainersigwald should we change common.tasks in msbuild to have a comment that says more less "if you change this lest, you also need to change this file in the .NET SDK"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added a note here and to msbuild: dotnet/msbuild#10351 |
||
<UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.Csc" AssemblyFile="$(RoslynTargetsPath)\Microsoft.Build.Tasks.CodeAnalysis.dll" /> | ||
<UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.Vbc" AssemblyFile="$(RoslynTargetsPath)\Microsoft.Build.Tasks.CodeAnalysis.dll" /> | ||
|
||
<ItemGroup Condition="'$(BuildWithNetFrameworkHostedCompiler)' == 'true' and '$(OS)' == 'Windows_NT' "> | ||
<PackageReference Include="Microsoft.Net.Compilers.Toolset.Framework" PrivateAssets="all" Version="$(_NetFrameworkHostedCompilersVersion)" IsImplicitlyDefined="true" /> | ||
</ItemGroup> | ||
<ItemGroup Condition="'$(_NeedToDownloadMicrosoftNetSdkCompilersToolsetPackage)' == 'true'"> | ||
<PackageDownload Include="Microsoft.Net.Sdk.Compilers.Toolset" Version="[$(NETCoreSdkVersion)]" /> | ||
</ItemGroup> | ||
|
||
<Target Name="_CheckMicrosoftNetSdkCompilersToolsetPackageReference" Condition="'$(_NeedToDownloadMicrosoftNetSdkCompilersToolsetPackage)' == 'true'" BeforeTargets="CollectPackageReferences"> | ||
<!-- Users should not be setting Microsoft.Net.Compilers.Toolset.Framework directly. | ||
If they do, and BuildWithNetFrameworkHostedCompiler is also set, the former will override the latter. | ||
This makes it more explicit that that is not supported. --> | ||
<NETSdkWarning ResourceName="CannotDirectlyReferenceMicrosoftNetCompilersToolsetFramework" | ||
Condition="'@(PackageReference->AnyHaveMetadataValue('Identity', 'Microsoft.Net.Compilers.Toolset.Framework'))' == 'true'" /> | ||
</Target> | ||
|
||
<!-- TODO: this target should not check GeneratePackageOnBuild. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ public GivenThatWeWantToUseFrameworkRoslyn(ITestOutputHelper log) : base(log) | |
} | ||
|
||
[FullMSBuildOnlyFact] | ||
public void It_restores_Microsoft_Net_Compilers_Toolset_Framework_when_requested() | ||
public void It_downloads_Microsoft_Net_Compilers_Toolset_Framework_when_requested() | ||
{ | ||
const string testProjectName = "NetCoreApp"; | ||
var project = new TestProject | ||
|
@@ -24,21 +24,19 @@ public void It_restores_Microsoft_Net_Compilers_Toolset_Framework_when_requested | |
var testAsset = _testAssetsManager | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't comment on it but then we should change the name of this test now to |
||
.CreateTestProject(project); | ||
|
||
string projectAssetsJsonPath = Path.Combine( | ||
testAsset.Path, | ||
project.Name, | ||
"obj", | ||
"project.assets.json"); | ||
NuGetConfigWriter.Write(testAsset.Path, TestContext.Current.TestPackages); | ||
|
||
var restoreCommand = | ||
testAsset.GetRestoreCommand(Log, relativePath: testProjectName); | ||
restoreCommand.Execute().Should().Pass(); | ||
var customPackageDir = Path.Combine(testAsset.Path, "nuget-packages"); | ||
|
||
Assert.Contains("Microsoft.Net.Compilers.Toolset.Framework", File.ReadAllText(projectAssetsJsonPath)); | ||
testAsset.GetRestoreCommand(Log, relativePath: testProjectName) | ||
.WithEnvironmentVariable("NUGET_PACKAGES", customPackageDir) | ||
.Execute().Should().Pass(); | ||
|
||
Assert.True(Directory.Exists(Path.Combine(customPackageDir, "microsoft.net.sdk.compilers.toolset"))); | ||
} | ||
|
||
[FullMSBuildOnlyFact] | ||
public void It_restores_Microsoft_Net_Compilers_Toolset_Framework_when_MSBuild_is_torn() | ||
public void It_downloads_Microsoft_Net_Compilers_Toolset_Framework_when_MSBuild_is_torn() | ||
{ | ||
const string testProjectName = "NetCoreApp"; | ||
var project = new TestProject | ||
|
@@ -53,24 +51,15 @@ public void It_restores_Microsoft_Net_Compilers_Toolset_Framework_when_MSBuild_i | |
var testAsset = _testAssetsManager | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment about name change |
||
.CreateTestProject(project); | ||
|
||
string projectAssetsJsonPath = Path.Combine( | ||
testAsset.Path, | ||
project.Name, | ||
"obj", | ||
"project.assets.json"); | ||
NuGetConfigWriter.Write(testAsset.Path, TestContext.Current.TestPackages); | ||
|
||
var restoreCommand = | ||
testAsset.GetRestoreCommand(Log, relativePath: testProjectName); | ||
restoreCommand.Execute().Should().Pass(); | ||
var customPackageDir = Path.Combine(testAsset.Path, "nuget-packages"); | ||
|
||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
{ | ||
Assert.Contains("Microsoft.Net.Compilers.Toolset.Framework", File.ReadAllText(projectAssetsJsonPath)); | ||
} | ||
else | ||
{ | ||
Assert.DoesNotContain("Microsoft.Net.Compilers.Toolset.Framework", File.ReadAllText(projectAssetsJsonPath)); | ||
} | ||
testAsset.GetRestoreCommand(Log, relativePath: testProjectName) | ||
.WithEnvironmentVariable("NUGET_PACKAGES", customPackageDir) | ||
.Execute().Should().Pass(); | ||
|
||
Assert.True(Directory.Exists(Path.Combine(customPackageDir, "microsoft.net.sdk.compilers.toolset"))); | ||
} | ||
|
||
[FullMSBuildOnlyFact] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two follow up items:
/p:RoslynTargetsPath=...\net472
. That will help ensure our test coverage catches any authoring mistakes we make in roslyn.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.