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

fix(dotnet): Ensure that packages can be updated when referencing .NET workloads #10649

Merged
merged 8 commits into from
Oct 22, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -3068,6 +3068,42 @@ await TestNoChangeforProject("Some.Package", "7.0.1", "13.0.1",
);
}

[Fact]
public async Task ProcessingProjectWithWorkloadReferencesDoesNotFail()
{
// enumerating the build files will fail if the Aspire workload is not installed; this test ensures we can
// still process the update
await TestUpdateForProject("Some.Package", "7.0.1", "13.0.1",
packages:
[
MockNuGetPackage.CreateSimplePackage("Some.Package", "7.0.1", "net8.0"),
MockNuGetPackage.CreateSimplePackage("Some.Package", "13.0.1", "net8.0"),
],
projectContents: """
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0-ios;net8.0-android;net8.0-macos;net8.0-maccatalyst;</TargetFrameworks>
<IsAspireHost>true</IsAspireHost>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Some.Package" Version="7.0.1" />
</ItemGroup>
</Project>
""",
expectedProjectContents: """
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0-ios;net8.0-android;net8.0-macos;net8.0-maccatalyst;</TargetFrameworks>
<IsAspireHost>true</IsAspireHost>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Some.Package" Version="13.0.1" />
</ItemGroup>
</Project>
"""
);
}

[Fact]
public async Task ProcessingProjectWithAspireDoesNotFailEvenThoughWorkloadIsNotInstalled()
{
Expand Down Expand Up @@ -3144,6 +3180,47 @@ await TestUpdateForProject("Some.Package", "7.0.1", "13.0.1",
);
}


[Theory]
[InlineData(true)]
[InlineData(false)]
public async Task ProjectWithWorkloadsShouldNotFail(bool useDependencySolver)
{
using var _ = new DependencySolverEnvironment(useDependencySolver);

// the property `$(SomeUnresolvableProperty)` cannot be resolved
await TestUpdateForProject("Some.Package", "7.0.1", "13.0.1",
packages:
[
MockNuGetPackage.CreateSimplePackage("Some.Package", "7.0.1", "net8.0"),
MockNuGetPackage.CreateSimplePackage("Some.Package", "13.0.1", "net8.0"),
MockNuGetPackage.CreateSimplePackage("Some.Other.Package", "1.0.0", "net8.0"),
],
projectContents: """
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net8.0-ios;net8.0-android;net8.0-macos;net8.0-maccatalyst</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Some.Other.Package" Version="$(SomeUnresolvableProperty)" />
<PackageReference Include="Some.Package" Version="7.0.1" />
</ItemGroup>
</Project>
""",
expectedProjectContents: """
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net8.0-ios;net8.0-android;net8.0-macos;net8.0-maccatalyst</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Some.Other.Package" Version="$(SomeUnresolvableProperty)" />
<PackageReference Include="Some.Package" Version="13.0.1" />
</ItemGroup>
</Project>
"""
);
}

[Theory]
[InlineData(true)]
[InlineData(false)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,44 @@ await File.WriteAllTextAsync(projectPath, """
}
}

[Fact]
public void UpdateWithWorkloadsTargetFrameworks()
{
// Arrange
var projectContents = """
<Project>
<PropertyGroup>
<TargetFrameworks>net8.0-ios;net8.0-android;net8.0-macos;net8.0-maccatalyst;</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Some.Package" Version="$(PackageVersion1)" />
</ItemGroup>
</Project>
""";
var propertyInfo = new Dictionary<string, Property>
{
{ "PackageVersion1", new("PackageVersion1", "1.1.1", "Packages.props") },
};

// Act
var (resultType, _, evaluatedValue, _, _) = MSBuildHelper.GetEvaluatedValue(projectContents, propertyInfo);

Assert.Equal(EvaluationResultType.Success, resultType);

// Assert
Assert.Equal("""
<Project>
<PropertyGroup>
<TargetFrameworks>net8.0-ios;net8.0-android;net8.0-macos;net8.0-maccatalyst;</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Some.Package" Version="1.1.1" />
</ItemGroup>
</Project>
""", evaluatedValue);
}


#region
// Updating root package
// CS-Script Code to 2.0.0 requires its dependency Microsoft.CodeAnalysis.CSharp.Scripting to be 3.6.0 and its transitive dependency Microsoft.CodeAnalysis.Common to be 3.6.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,8 @@ internal static async Task<string> CreateTempProjectAsync(
<GenerateDependencyFile>true</GenerateDependencyFile>
<RunAnalyzers>false</RunAnalyzers>
<NuGetInteractive>false</NuGetInteractive>
<DesignTimeBuild>true</DesignTimeBuild>
<TargetPlatformVersion Condition=" $(TargetFramework.Contains('-')) ">1.0</TargetPlatformVersion>
</PropertyGroup>
<ItemGroup>
{packageReferences}
Expand Down
Loading