-
Notifications
You must be signed in to change notification settings - Fork 686
Allow referencing older version of AppHost package for backward compatibility #5556
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
Changes from all commits
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 |
---|---|---|
|
@@ -71,13 +71,17 @@ | |
<_AppHostVersion>%(_AppHostPackageReference.Version)</_AppHostVersion> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(_AppHostVersion)' != ''"> | ||
<__CurrentAppHostVersionMessage> You are using version $(_AppHostVersion).</__CurrentAppHostVersionMessage> | ||
<PropertyGroup Condition="'$(_AppHostVersion)' != '' and $([MSBuild]::VersionLessThan('$(_AppHostVersion)', '8.2.0'))"> | ||
<!-- If we find the version to Aspire.Hosting.AppHost package but it is lower than 8.2.0, then we fall back | ||
to use the Dashboard and DCP packages that match the version of the installed workload for backwards compatibility. | ||
This results in the same behavior that we had before moving Dashboard and DCP out of the workload, since the version | ||
is again just matching to the one the workload has. --> | ||
<_AppHostVersion>@VERSION@</_AppHostVersion> | ||
</PropertyGroup> | ||
|
||
<!-- At this point, we should have the version either by CPM or PackageReference, so we fail if not. --> | ||
<Error Condition="'$(_AppHostVersion)' == '' or $([MSBuild]::VersionLessThan('$(_AppHostVersion)', '8.2.0'))" | ||
Text="$(MSBuildProjectName) is a .NET Aspire AppHost project that needs a package reference to Aspire.Hosting.AppHost version 8.2.0 or above to work correctly.$(__CurrentAppHostVersionMessage)" /> | ||
<Error Condition="'$(_AppHostVersion)' == ''" | ||
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. A test for this would be good too. It doesn't have to be in this PR. 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'll add more tests to this whole scenario with the changes on the Aspire Workload for 9.0 |
||
Text="$(MSBuildProjectName) is a .NET Aspire AppHost project that needs a package reference to Aspire.Hosting.AppHost version 8.2.0 or above to work correctly." /> | ||
|
||
<!-- Now that we have the version, we add the package references --> | ||
<ItemGroup> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Xunit; | ||
using Xunit.Abstractions; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace Aspire.Workload.Tests; | ||
|
||
public partial class AppHostTemplateTests : WorkloadTestsBase | ||
{ | ||
public AppHostTemplateTests(ITestOutputHelper testOutput) | ||
: base(testOutput) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public async Task EnsureProjectsReferencing8_1_0AppHostWithNewerWorkloadCanBuild() | ||
{ | ||
string projectId = "aspire-can-reference-8.1.0"; | ||
await using var project = await AspireProject.CreateNewTemplateProjectAsync( | ||
projectId, | ||
"aspire-apphost", | ||
radical marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_testOutput, | ||
BuildEnvironment.ForDefaultFramework, | ||
string.Empty, | ||
false); | ||
|
||
var projectPath = Path.Combine(project.RootDir, $"{projectId}.csproj"); | ||
|
||
// Replace the reference to Aspire.Hosting.AppHost with version 8.1.0 | ||
var newContents = AppHostPackageReferenceRegex().Replace(File.ReadAllText(projectPath), @"$1""8.1.0"""); | ||
|
||
File.WriteAllText(projectPath, newContents); | ||
|
||
// Ensure project builds successfully | ||
await project.BuildAsync(workingDirectory: project.RootDir); | ||
} | ||
|
||
[GeneratedRegex(@"(PackageReference\s.*""Aspire\.Hosting\.AppHost.*Version=)""[^""]+""")] | ||
private static partial Regex AppHostPackageReferenceRegex(); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.