From 4fc34967500a9e12cee9f98fd680de7513a92791 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Fri, 19 Jan 2024 12:37:28 -0600 Subject: [PATCH 01/13] Refactor ProjectReferences in AppHost At a high-level there are 2 problems with how we are using ProjectReference to reference the individual "service application" projects in the AppHost. 1. The AppHost may not have a compatible TFM with the referenced application project. For example if the referenced application project was targeting `net8-windows`. 2. When we are generating IServiceMetadata code, we are using ReferencePathWithRefAssemblies items, which means if the ProjectReference has ReferenceOutputAssembly="false" on it, no IServiceMetadata code will be generated. To resolve these issues, we are taking the following approach: - By default ProjectReferences in the AppHost will mean a reference to a "service application", and not a regular project reference. If an AppHost project truly wants a ProjectReference to another project, it can be marked as ``. - ProjectReferences to service applications will be marked `ReferenceOutputAssembly=false`, `SkipGetTargetFrameworkProperties=true`, `ExcludeAssets=all`. This will cause the AppHost to not reference the service app projects. - Refactor the IServiceMetadata code gen to act directly on ProjectReference items. Fix #1074 Fix #1563 --- playground/dapr/AppHost/DaprAppHost.csproj | 5 +- playground/eShopLite/AppHost/AppHost.csproj | 7 +- .../OrleansAppHost/OrleansAppHost.csproj | 7 +- .../build/Aspire.Hosting.targets | 93 +++++++++---------- .../Aspire.Hosting.Tests.csproj | 15 ++- .../TestProject.AppHost.csproj | 5 +- 6 files changed, 71 insertions(+), 61 deletions(-) diff --git a/playground/dapr/AppHost/DaprAppHost.csproj b/playground/dapr/AppHost/DaprAppHost.csproj index c904c982fa..d6da34390d 100644 --- a/playground/dapr/AppHost/DaprAppHost.csproj +++ b/playground/dapr/AppHost/DaprAppHost.csproj @@ -9,8 +9,9 @@ - - + + + diff --git a/playground/eShopLite/AppHost/AppHost.csproj b/playground/eShopLite/AppHost/AppHost.csproj index a08dd96dbf..5df276ffc9 100644 --- a/playground/eShopLite/AppHost/AppHost.csproj +++ b/playground/eShopLite/AppHost/AppHost.csproj @@ -10,9 +10,10 @@ - - - + + + + diff --git a/playground/orleans/OrleansAppHost/OrleansAppHost.csproj b/playground/orleans/OrleansAppHost/OrleansAppHost.csproj index 0c39f8fd3b..51556d4cbd 100644 --- a/playground/orleans/OrleansAppHost/OrleansAppHost.csproj +++ b/playground/orleans/OrleansAppHost/OrleansAppHost.csproj @@ -10,9 +10,10 @@ - - - + + + + diff --git a/src/Aspire.Hosting/build/Aspire.Hosting.targets b/src/Aspire.Hosting/build/Aspire.Hosting.targets index e2b19eb694..d493f1a833 100644 --- a/src/Aspire.Hosting/build/Aspire.Hosting.targets +++ b/src/Aspire.Hosting/build/Aspire.Hosting.targets @@ -12,17 +12,27 @@ + + + + + true + + false + true + all + + + <_ServiceAppProject Include="@(ProjectReference->WithMetadataValue('IsServiceApp', 'true'))" /> + + - + - - $([System.IO.Path]::GetFileNameWithoutExtension(%(ReferencePathWithRefAssemblies.Identity)).Replace(".", "_").Replace("-","_").Replace(" ","_")) - $([System.String]::Copy(%(ReferencePathWithRefAssemblies.ServiceNameOverride)).Replace(".", "_").Replace("-","_").Replace(" ","_")) - $([System.IO.Path]::GetFileNameWithoutExtension(%(ReferencePathWithRefAssemblies.Identity))) - $([System.IO.Path]::GetFullPath(%(ReferencePathWithRefAssemblies.ProjectReferenceOriginalItemSpec))) + + $([System.IO.Path]::GetFileNameWithoutExtension(%(_ServiceAppProject.Identity)).Replace(".", "_").Replace("-","_").Replace(" ","_")) + $([System.String]::Copy(%(_ServiceAppProject.ServiceNameOverride)).Replace(".", "_").Replace("-","_").Replace(" ","_")) + $([System.IO.Path]::GetFullPath(%(_ServiceAppProject.Identity))) Projects @@ -32,12 +42,10 @@ - %(Namespace)%(Namespace)%(ClassName)%(ClassName) """]]>%(ProjectPath) @@ -45,20 +53,16 @@ public class ]]>%(ClassName) - + - - + + @@ -75,9 +79,7 @@ public class ]]>%(ClassName) - Projects%(ClassName)%(ClassName) - + @@ -106,12 +106,12 @@ internal static class ]]>%(ClassName) - <_WriteServiceMetadataSourcesDependsOn>_CSharpWriteServiceMetadataSources;_CSharpAppHostProjectMetadataSources;_WarnOnUnsupportedLanguage + _CSharpWriteServiceMetadataSources;_CSharpAppHostProjectMetadataSources;_WarnOnUnsupportedLanguage - - + + @@ -157,11 +157,10 @@ internal static class ]]>%(ClassName) + ConsoleToMsBuild="true" + IgnoreStandardErrorWarningFormat="true" + EchoOff="true" + StandardOutputImportance="low" + StandardErrorImportance="low" /> diff --git a/tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj b/tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj index 4f1e89098c..08287e5cf7 100644 --- a/tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj +++ b/tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj @@ -8,11 +8,18 @@ - - - - + + + + + + + + + + + diff --git a/tests/testproject/TestProject.AppHost/TestProject.AppHost.csproj b/tests/testproject/TestProject.AppHost/TestProject.AppHost.csproj index b2547a35c4..49bbdae108 100644 --- a/tests/testproject/TestProject.AppHost/TestProject.AppHost.csproj +++ b/tests/testproject/TestProject.AppHost/TestProject.AppHost.csproj @@ -9,8 +9,9 @@ - - + + + From dc6235b2c450a92fe318a4c633a9dd8289b76014 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Fri, 19 Jan 2024 15:54:11 -0600 Subject: [PATCH 02/13] Move ProjectReference defaulting logic into the SDK targets so it is respected by NuGet Restore --- src/Aspire.Hosting.Sdk/SDK/Sdk.targets | 18 +++++++++++++++--- .../build/Aspire.Hosting.targets | 19 +++---------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/Aspire.Hosting.Sdk/SDK/Sdk.targets b/src/Aspire.Hosting.Sdk/SDK/Sdk.targets index 1756041ed7..f8cbd4ca2f 100644 --- a/src/Aspire.Hosting.Sdk/SDK/Sdk.targets +++ b/src/Aspire.Hosting.Sdk/SDK/Sdk.targets @@ -1,7 +1,5 @@ - - + + + + + <_IsServiceApp Condition="'%(_IsServiceApp)' == '' and '%(AppHostLibrary)' != 'true'">true + + false + true + all + + + diff --git a/src/Aspire.Hosting/build/Aspire.Hosting.targets b/src/Aspire.Hosting/build/Aspire.Hosting.targets index d493f1a833..c8e78222b7 100644 --- a/src/Aspire.Hosting/build/Aspire.Hosting.targets +++ b/src/Aspire.Hosting/build/Aspire.Hosting.targets @@ -12,28 +12,15 @@ - - - - - true - - false - true - all - - - <_ServiceAppProject Include="@(ProjectReference->WithMetadataValue('IsServiceApp', 'true'))" /> - - + <_ServiceAppProject Include="@(ProjectReference->WithMetadataValue('_IsServiceApp', 'true'))" /> + $([System.IO.Path]::GetFileNameWithoutExtension(%(_ServiceAppProject.Identity)).Replace(".", "_").Replace("-","_").Replace(" ","_")) $([System.String]::Copy(%(_ServiceAppProject.ServiceNameOverride)).Replace(".", "_").Replace("-","_").Replace(" ","_")) $([System.IO.Path]::GetFullPath(%(_ServiceAppProject.Identity))) - Projects @@ -42,7 +29,7 @@ - %(Namespace)%(ClassName) Date: Fri, 19 Jan 2024 16:58:59 -0600 Subject: [PATCH 03/13] Fix test AppHost projects to also import the SDK.targets --- playground/dapr/AppHost/Directory.Build.targets | 5 +++-- playground/eShopLite/AppHost/Directory.Build.targets | 7 ++++--- playground/orleans/OrleansAppHost/Directory.Build.targets | 7 ++++--- .../TestProject.AppHost/Directory.Build.targets | 5 +++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/playground/dapr/AppHost/Directory.Build.targets b/playground/dapr/AppHost/Directory.Build.targets index 6ca05913d2..7100653568 100644 --- a/playground/dapr/AppHost/Directory.Build.targets +++ b/playground/dapr/AppHost/Directory.Build.targets @@ -2,7 +2,8 @@ - + - + + diff --git a/playground/eShopLite/AppHost/Directory.Build.targets b/playground/eShopLite/AppHost/Directory.Build.targets index 281a6cb2fc..112ac8875d 100644 --- a/playground/eShopLite/AppHost/Directory.Build.targets +++ b/playground/eShopLite/AppHost/Directory.Build.targets @@ -2,7 +2,8 @@ - - - + + + + diff --git a/playground/orleans/OrleansAppHost/Directory.Build.targets b/playground/orleans/OrleansAppHost/Directory.Build.targets index 281a6cb2fc..112ac8875d 100644 --- a/playground/orleans/OrleansAppHost/Directory.Build.targets +++ b/playground/orleans/OrleansAppHost/Directory.Build.targets @@ -2,7 +2,8 @@ - - - + + + + diff --git a/tests/testproject/TestProject.AppHost/Directory.Build.targets b/tests/testproject/TestProject.AppHost/Directory.Build.targets index 66914d63d1..112ac8875d 100644 --- a/tests/testproject/TestProject.AppHost/Directory.Build.targets +++ b/tests/testproject/TestProject.AppHost/Directory.Build.targets @@ -2,7 +2,8 @@ - + - + + From 8290c72d01e594fedf23bad08fbe2b78e51e169d Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Fri, 19 Jan 2024 17:08:44 -0600 Subject: [PATCH 04/13] Suppress importing the orchestration SDK targets in test AppHosts, so the projects build even if the workload is not installed. --- playground/dapr/AppHost/Directory.Build.targets | 3 +++ playground/eShopLite/AppHost/Directory.Build.targets | 3 +++ playground/orleans/OrleansAppHost/Directory.Build.targets | 3 +++ src/Aspire.Hosting.Sdk/SDK/Sdk.targets | 2 +- tests/testproject/TestProject.AppHost/Directory.Build.targets | 3 +++ 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/playground/dapr/AppHost/Directory.Build.targets b/playground/dapr/AppHost/Directory.Build.targets index 7100653568..8d341d24bc 100644 --- a/playground/dapr/AppHost/Directory.Build.targets +++ b/playground/dapr/AppHost/Directory.Build.targets @@ -3,6 +3,9 @@ + + <_SuppressImportAspireHostingOrchestrationTargets>true + diff --git a/playground/eShopLite/AppHost/Directory.Build.targets b/playground/eShopLite/AppHost/Directory.Build.targets index 112ac8875d..5bc3054c7b 100644 --- a/playground/eShopLite/AppHost/Directory.Build.targets +++ b/playground/eShopLite/AppHost/Directory.Build.targets @@ -3,6 +3,9 @@ + + <_SuppressImportAspireHostingOrchestrationTargets>true + diff --git a/playground/orleans/OrleansAppHost/Directory.Build.targets b/playground/orleans/OrleansAppHost/Directory.Build.targets index 112ac8875d..5bc3054c7b 100644 --- a/playground/orleans/OrleansAppHost/Directory.Build.targets +++ b/playground/orleans/OrleansAppHost/Directory.Build.targets @@ -3,6 +3,9 @@ + + <_SuppressImportAspireHostingOrchestrationTargets>true + diff --git a/src/Aspire.Hosting.Sdk/SDK/Sdk.targets b/src/Aspire.Hosting.Sdk/SDK/Sdk.targets index f8cbd4ca2f..c94ff5d21d 100644 --- a/src/Aspire.Hosting.Sdk/SDK/Sdk.targets +++ b/src/Aspire.Hosting.Sdk/SDK/Sdk.targets @@ -49,6 +49,6 @@ also contains Aspire.Hosting.Orchestration and vice versa. Once Aspire/DCP are public we can move it to WorkloadManifest.targets to ensure future correctness. --> - + diff --git a/tests/testproject/TestProject.AppHost/Directory.Build.targets b/tests/testproject/TestProject.AppHost/Directory.Build.targets index 112ac8875d..5bc3054c7b 100644 --- a/tests/testproject/TestProject.AppHost/Directory.Build.targets +++ b/tests/testproject/TestProject.AppHost/Directory.Build.targets @@ -3,6 +3,9 @@ + + <_SuppressImportAspireHostingOrchestrationTargets>true + From fdb8f605f7c1a5e851a5a7fa208f4616d5e49745 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Mon, 22 Jan 2024 13:01:52 -0600 Subject: [PATCH 05/13] Update CosmosEndToEnd app --- .../CosmosEndToEnd.AppHost/CosmosEndToEnd.AppHost.csproj | 5 +++-- .../CosmosEndToEnd.AppHost/Directory.Build.targets | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/playground/CosmosEndToEnd/CosmosEndToEnd.AppHost/CosmosEndToEnd.AppHost.csproj b/playground/CosmosEndToEnd/CosmosEndToEnd.AppHost/CosmosEndToEnd.AppHost.csproj index 2e9d5a87f0..f57e4618e3 100644 --- a/playground/CosmosEndToEnd/CosmosEndToEnd.AppHost/CosmosEndToEnd.AppHost.csproj +++ b/playground/CosmosEndToEnd/CosmosEndToEnd.AppHost/CosmosEndToEnd.AppHost.csproj @@ -9,8 +9,9 @@ - - + + + diff --git a/playground/CosmosEndToEnd/CosmosEndToEnd.AppHost/Directory.Build.targets b/playground/CosmosEndToEnd/CosmosEndToEnd.AppHost/Directory.Build.targets index 281a6cb2fc..cd4fce831a 100644 --- a/playground/CosmosEndToEnd/CosmosEndToEnd.AppHost/Directory.Build.targets +++ b/playground/CosmosEndToEnd/CosmosEndToEnd.AppHost/Directory.Build.targets @@ -2,7 +2,11 @@ - - + + + <_SuppressImportAspireHostingOrchestrationTargets>true + + + From 9f8a8531f6efff203cae0d0c4fb9f318c7df324a Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Mon, 22 Jan 2024 13:08:22 -0600 Subject: [PATCH 06/13] Rename AppHostLibrary => AspireHostLibrary --- .../CosmosEndToEnd.AppHost.csproj | 4 ++-- playground/dapr/AppHost/DaprAppHost.csproj | 4 ++-- playground/eShopLite/AppHost/AppHost.csproj | 6 +++--- .../orleans/OrleansAppHost/OrleansAppHost.csproj | 6 +++--- src/Aspire.Hosting.Sdk/SDK/Sdk.targets | 4 ++-- .../Aspire.Hosting.Tests.csproj | 16 ++++++++-------- .../TestProject.AppHost.csproj | 4 ++-- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/playground/CosmosEndToEnd/CosmosEndToEnd.AppHost/CosmosEndToEnd.AppHost.csproj b/playground/CosmosEndToEnd/CosmosEndToEnd.AppHost/CosmosEndToEnd.AppHost.csproj index f57e4618e3..a1c1a1e405 100644 --- a/playground/CosmosEndToEnd/CosmosEndToEnd.AppHost/CosmosEndToEnd.AppHost.csproj +++ b/playground/CosmosEndToEnd/CosmosEndToEnd.AppHost/CosmosEndToEnd.AppHost.csproj @@ -9,8 +9,8 @@ - - + + diff --git a/playground/dapr/AppHost/DaprAppHost.csproj b/playground/dapr/AppHost/DaprAppHost.csproj index d6da34390d..6c47480876 100644 --- a/playground/dapr/AppHost/DaprAppHost.csproj +++ b/playground/dapr/AppHost/DaprAppHost.csproj @@ -9,8 +9,8 @@ - - + + diff --git a/playground/eShopLite/AppHost/AppHost.csproj b/playground/eShopLite/AppHost/AppHost.csproj index 5df276ffc9..c1f995a003 100644 --- a/playground/eShopLite/AppHost/AppHost.csproj +++ b/playground/eShopLite/AppHost/AppHost.csproj @@ -10,9 +10,9 @@ - - - + + + diff --git a/playground/orleans/OrleansAppHost/OrleansAppHost.csproj b/playground/orleans/OrleansAppHost/OrleansAppHost.csproj index 51556d4cbd..49c6dd8d59 100644 --- a/playground/orleans/OrleansAppHost/OrleansAppHost.csproj +++ b/playground/orleans/OrleansAppHost/OrleansAppHost.csproj @@ -10,9 +10,9 @@ - - - + + + diff --git a/src/Aspire.Hosting.Sdk/SDK/Sdk.targets b/src/Aspire.Hosting.Sdk/SDK/Sdk.targets index c94ff5d21d..40e58d981a 100644 --- a/src/Aspire.Hosting.Sdk/SDK/Sdk.targets +++ b/src/Aspire.Hosting.Sdk/SDK/Sdk.targets @@ -19,13 +19,13 @@ - <_IsServiceApp Condition="'%(_IsServiceApp)' == '' and '%(AppHostLibrary)' != 'true'">true + <_IsServiceApp Condition="'%(_IsServiceApp)' == '' and '%(AspireHostLibrary)' != 'true'">true false true diff --git a/tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj b/tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj index 08287e5cf7..49396e1bf0 100644 --- a/tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj +++ b/tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj @@ -8,15 +8,15 @@ - - - + + + - - - - - + + + + + diff --git a/tests/testproject/TestProject.AppHost/TestProject.AppHost.csproj b/tests/testproject/TestProject.AppHost/TestProject.AppHost.csproj index 49bbdae108..cc2d5b3a5e 100644 --- a/tests/testproject/TestProject.AppHost/TestProject.AppHost.csproj +++ b/tests/testproject/TestProject.AppHost/TestProject.AppHost.csproj @@ -9,8 +9,8 @@ - - + + From 3917b311f84a7e47b6c6a70c446298545d5154c4 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Mon, 22 Jan 2024 18:05:47 -0600 Subject: [PATCH 07/13] Add a build warning informing developers when they ProjectReference a library in the AppHost, but didn't set AspireHostLibrary=true. --- playground/eShopLite/AppHost/AppHost.csproj | 2 +- .../build/Aspire.Hosting.targets | 82 ++++++++++++++++++- 2 files changed, 80 insertions(+), 4 deletions(-) diff --git a/playground/eShopLite/AppHost/AppHost.csproj b/playground/eShopLite/AppHost/AppHost.csproj index c1f995a003..af97c7940c 100644 --- a/playground/eShopLite/AppHost/AppHost.csproj +++ b/playground/eShopLite/AppHost/AppHost.csproj @@ -13,7 +13,7 @@ - + diff --git a/src/Aspire.Hosting/build/Aspire.Hosting.targets b/src/Aspire.Hosting/build/Aspire.Hosting.targets index c8e78222b7..ef7af9d59e 100644 --- a/src/Aspire.Hosting/build/Aspire.Hosting.targets +++ b/src/Aspire.Hosting/build/Aspire.Hosting.targets @@ -12,11 +12,18 @@ - - + + <_ServiceAppProject Include="@(ProjectReference->WithMetadataValue('_IsServiceApp', 'true'))" /> + + + + + + $([System.IO.Path]::GetFileNameWithoutExtension(%(_ServiceAppProject.Identity)).Replace(".", "_").Replace("-","_").Replace(" ","_")) $([System.String]::Copy(%(_ServiceAppProject.ServiceNameOverride)).Replace(".", "_").Replace("-","_").Replace(" ","_")) @@ -91,9 +98,78 @@ internal static class ]]>%(ClassName) + + + + + + + + + + nonExecutableReferences = new HashSet(); + + foreach (var appProject in AppProjectTargetFramework) + { + var additionalProperties = appProject.GetMetadata("AdditionalPropertiesFromProject"); + if (string.IsNullOrEmpty(additionalProperties)) + { + // Skip any projects that don't contain the right metadata + continue; + } + + var additionalPropertiesXml = XElement.Parse(additionalProperties); + foreach (var targetFrameworkElement in additionalPropertiesXml.Elements()) + { + var isExe = targetFrameworkElement.Element("_IsExecutable"); + if (isExe != null && !string.Equals(isExe.Value, "true", StringComparison.OrdinalIgnoreCase)) + { + nonExecutableReferences.Add(appProject); + } + } + } + + NonExecutableReferences = nonExecutableReferences.ToArray(); + ]]> + + + + + + + + + + + + + + + + + + - _CSharpWriteServiceMetadataSources;_CSharpAppHostProjectMetadataSources;_WarnOnUnsupportedLanguage + _CSharpWriteServiceMetadataSources;_CSharpAppHostProjectMetadataSources;_WarnOnUnsupportedLanguage;_ValidateAspireHostServiceReferences - <_IsServiceApp Condition="'%(_IsServiceApp)' == '' and '%(AspireHostLibrary)' != 'true'">true + <_IsServiceApp Condition="'%(_IsServiceApp)' == '' and '%(IsAspireHostLibrary)' != 'true'">true false true diff --git a/src/Aspire.Hosting/build/Aspire.Hosting.targets b/src/Aspire.Hosting/build/Aspire.Hosting.targets index ef7af9d59e..22b97d535d 100644 --- a/src/Aspire.Hosting/build/Aspire.Hosting.targets +++ b/src/Aspire.Hosting/build/Aspire.Hosting.targets @@ -142,7 +142,7 @@ internal static class ]]>%(ClassName) %(ClassName) + Text="'%(_NonExecutableServiceApps.OriginalItemSpec)' is referenced by an Aspire AppHost project, but it is not an executable. Did you mean to set IsAspireHostLibrary="true"?" /> diff --git a/tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj b/tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj index 49396e1bf0..44b49c5aa6 100644 --- a/tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj +++ b/tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj @@ -8,15 +8,15 @@ - - - + + + - - - - - + + + + + diff --git a/tests/Aspire.Hosting.Tests/MSBuildTests.cs b/tests/Aspire.Hosting.Tests/MSBuildTests.cs index 2e0dfe5364..cbae55957a 100644 --- a/tests/Aspire.Hosting.Tests/MSBuildTests.cs +++ b/tests/Aspire.Hosting.Tests/MSBuildTests.cs @@ -56,7 +56,7 @@ public class Class1 - + @@ -87,7 +87,7 @@ public class Class1 var output = new StringBuilder(); var outputDone = new ManualResetEvent(false); - var process = new Process(); + using var process = new Process(); // set '-nodereuse:false -p:UseSharedCompilation=false' so the MSBuild and Roslyn server processes don't hang around, which may hang the test in CI process.StartInfo = new ProcessStartInfo("dotnet", $"build -nodereuse:false -p:UseSharedCompilation=false") { diff --git a/tests/testproject/TestProject.AppHost/TestProject.AppHost.csproj b/tests/testproject/TestProject.AppHost/TestProject.AppHost.csproj index cc2d5b3a5e..78ade1c1e5 100644 --- a/tests/testproject/TestProject.AppHost/TestProject.AppHost.csproj +++ b/tests/testproject/TestProject.AppHost/TestProject.AppHost.csproj @@ -9,8 +9,8 @@ - - + + From f9eb38313322dbaf33be065871d3e790fb0d9685 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Wed, 24 Jan 2024 12:43:57 -0600 Subject: [PATCH 11/13] Fix up merge --- .../CosmosEndToEnd.AppHost/CosmosEndToEnd.AppHost.csproj | 2 +- playground/dapr/AppHost/DaprAppHost.csproj | 4 ++-- playground/eShopLite/AppHost/AppHost.csproj | 2 +- playground/orleans/OrleansAppHost/OrleansAppHost.csproj | 2 +- playground/orleans/OrleansAppHost/Program.cs | 2 -- 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/playground/CosmosEndToEnd/CosmosEndToEnd.AppHost/CosmosEndToEnd.AppHost.csproj b/playground/CosmosEndToEnd/CosmosEndToEnd.AppHost/CosmosEndToEnd.AppHost.csproj index 1d1b036882..4ca0fd99e1 100644 --- a/playground/CosmosEndToEnd/CosmosEndToEnd.AppHost/CosmosEndToEnd.AppHost.csproj +++ b/playground/CosmosEndToEnd/CosmosEndToEnd.AppHost/CosmosEndToEnd.AppHost.csproj @@ -13,7 +13,7 @@ - + diff --git a/playground/dapr/AppHost/DaprAppHost.csproj b/playground/dapr/AppHost/DaprAppHost.csproj index a8aef144e6..19d1250398 100644 --- a/playground/dapr/AppHost/DaprAppHost.csproj +++ b/playground/dapr/AppHost/DaprAppHost.csproj @@ -13,10 +13,10 @@ - + - + diff --git a/playground/eShopLite/AppHost/AppHost.csproj b/playground/eShopLite/AppHost/AppHost.csproj index b4a19e6cf6..cbdf6fbd7c 100644 --- a/playground/eShopLite/AppHost/AppHost.csproj +++ b/playground/eShopLite/AppHost/AppHost.csproj @@ -14,7 +14,7 @@ - + diff --git a/playground/orleans/OrleansAppHost/OrleansAppHost.csproj b/playground/orleans/OrleansAppHost/OrleansAppHost.csproj index 3a3e24e667..23c2ae436d 100644 --- a/playground/orleans/OrleansAppHost/OrleansAppHost.csproj +++ b/playground/orleans/OrleansAppHost/OrleansAppHost.csproj @@ -14,7 +14,7 @@ - + diff --git a/playground/orleans/OrleansAppHost/Program.cs b/playground/orleans/OrleansAppHost/Program.cs index f051b5e146..afa2252055 100644 --- a/playground/orleans/OrleansAppHost/Program.cs +++ b/playground/orleans/OrleansAppHost/Program.cs @@ -1,5 +1,3 @@ -using Microsoft.Extensions.Hosting; - var builder = DistributedApplication.CreateBuilder(args); var storage = builder.AddAzureStorage("storage"); From a005c5a128cadd497fabe1f2e051fb79de6bbefb Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Wed, 24 Jan 2024 14:42:59 -0600 Subject: [PATCH 12/13] Rename ProjectReference properties - IsAspireProjectResource=false - Setting this to false opts you into being an "AppHost library", you don't get "Projects" code generated, and you start referencing the project - ServiceNameOverride => AspireProjectMetadataTypeName This also allows us to rename IServiceMetadata to IProjectMetadata. --- .../CosmosEndToEnd.AppHost.csproj | 4 +- .../Directory.Build.targets | 3 - playground/dapr/AppHost/DaprAppHost.csproj | 4 +- .../dapr/AppHost/Directory.Build.targets | 3 - playground/eShopLite/AppHost/AppHost.csproj | 6 +- .../eShopLite/AppHost/Directory.Build.targets | 3 - .../OrleansAppHost/Directory.Build.targets | 3 - .../OrleansAppHost/OrleansAppHost.csproj | 6 +- src/Aspire.Hosting.Sdk/SDK/Sdk.targets | 10 +-- .../ProjectResourceExtensions.cs | 12 +-- src/Aspire.Hosting/Dcp/ApplicationExecutor.cs | 2 +- .../ProjectResourceBuilderExtensions.cs | 4 +- ...ServiceMetadata.cs => IProjectMetadata.cs} | 8 +- .../Properties/Resources.Designer.cs | 6 +- src/Aspire.Hosting/Properties/Resources.resx | 4 +- .../Properties/xlf/Resources.cs.xlf | 6 +- .../Properties/xlf/Resources.de.xlf | 6 +- .../Properties/xlf/Resources.es.xlf | 6 +- .../Properties/xlf/Resources.fr.xlf | 6 +- .../Properties/xlf/Resources.it.xlf | 6 +- .../Properties/xlf/Resources.ja.xlf | 6 +- .../Properties/xlf/Resources.ko.xlf | 6 +- .../Properties/xlf/Resources.pl.xlf | 6 +- .../Properties/xlf/Resources.pt-BR.xlf | 6 +- .../Properties/xlf/Resources.ru.xlf | 6 +- .../Properties/xlf/Resources.tr.xlf | 6 +- .../Properties/xlf/Resources.zh-Hans.xlf | 6 +- .../Properties/xlf/Resources.zh-Hant.xlf | 6 +- ...icManifestPublisherBindingInjectionHook.cs | 4 +- .../Publishing/ManifestPublisher.cs | 4 +- .../Utils/LaunchProfileExtensions.cs | 14 +-- .../build/Aspire.Hosting.targets | 86 +++++++++---------- .../Aspire.Hosting.Tests.csproj | 16 ++-- tests/Aspire.Hosting.Tests/MSBuildTests.cs | 3 +- .../ProjectResourceTests.cs | 4 +- .../Directory.Build.targets | 3 - .../TestProject.AppHost.csproj | 14 +-- 37 files changed, 144 insertions(+), 160 deletions(-) rename src/Aspire.Hosting/{IServiceMetadata.cs => IProjectMetadata.cs} (66%) diff --git a/playground/CosmosEndToEnd/CosmosEndToEnd.AppHost/CosmosEndToEnd.AppHost.csproj b/playground/CosmosEndToEnd/CosmosEndToEnd.AppHost/CosmosEndToEnd.AppHost.csproj index 4ca0fd99e1..f5a2e4c258 100644 --- a/playground/CosmosEndToEnd/CosmosEndToEnd.AppHost/CosmosEndToEnd.AppHost.csproj +++ b/playground/CosmosEndToEnd/CosmosEndToEnd.AppHost/CosmosEndToEnd.AppHost.csproj @@ -14,8 +14,8 @@ - - + + diff --git a/playground/CosmosEndToEnd/CosmosEndToEnd.AppHost/Directory.Build.targets b/playground/CosmosEndToEnd/CosmosEndToEnd.AppHost/Directory.Build.targets index cd4fce831a..b7ba77268f 100644 --- a/playground/CosmosEndToEnd/CosmosEndToEnd.AppHost/Directory.Build.targets +++ b/playground/CosmosEndToEnd/CosmosEndToEnd.AppHost/Directory.Build.targets @@ -3,9 +3,6 @@ - - <_SuppressImportAspireHostingOrchestrationTargets>true - diff --git a/playground/dapr/AppHost/DaprAppHost.csproj b/playground/dapr/AppHost/DaprAppHost.csproj index 19d1250398..5e95a15b1f 100644 --- a/playground/dapr/AppHost/DaprAppHost.csproj +++ b/playground/dapr/AppHost/DaprAppHost.csproj @@ -14,8 +14,8 @@ - - + + diff --git a/playground/dapr/AppHost/Directory.Build.targets b/playground/dapr/AppHost/Directory.Build.targets index 8d341d24bc..7100653568 100644 --- a/playground/dapr/AppHost/Directory.Build.targets +++ b/playground/dapr/AppHost/Directory.Build.targets @@ -3,9 +3,6 @@ - - <_SuppressImportAspireHostingOrchestrationTargets>true - diff --git a/playground/eShopLite/AppHost/AppHost.csproj b/playground/eShopLite/AppHost/AppHost.csproj index cbdf6fbd7c..2bb8821408 100644 --- a/playground/eShopLite/AppHost/AppHost.csproj +++ b/playground/eShopLite/AppHost/AppHost.csproj @@ -15,9 +15,9 @@ - - - + + + diff --git a/playground/eShopLite/AppHost/Directory.Build.targets b/playground/eShopLite/AppHost/Directory.Build.targets index 5bc3054c7b..112ac8875d 100644 --- a/playground/eShopLite/AppHost/Directory.Build.targets +++ b/playground/eShopLite/AppHost/Directory.Build.targets @@ -3,9 +3,6 @@ - - <_SuppressImportAspireHostingOrchestrationTargets>true - diff --git a/playground/orleans/OrleansAppHost/Directory.Build.targets b/playground/orleans/OrleansAppHost/Directory.Build.targets index 5bc3054c7b..112ac8875d 100644 --- a/playground/orleans/OrleansAppHost/Directory.Build.targets +++ b/playground/orleans/OrleansAppHost/Directory.Build.targets @@ -3,9 +3,6 @@ - - <_SuppressImportAspireHostingOrchestrationTargets>true - diff --git a/playground/orleans/OrleansAppHost/OrleansAppHost.csproj b/playground/orleans/OrleansAppHost/OrleansAppHost.csproj index 23c2ae436d..54492697cb 100644 --- a/playground/orleans/OrleansAppHost/OrleansAppHost.csproj +++ b/playground/orleans/OrleansAppHost/OrleansAppHost.csproj @@ -15,9 +15,9 @@ - - - + + + diff --git a/src/Aspire.Hosting.Sdk/SDK/Sdk.targets b/src/Aspire.Hosting.Sdk/SDK/Sdk.targets index 2fc67a8890..5e146c3851 100644 --- a/src/Aspire.Hosting.Sdk/SDK/Sdk.targets +++ b/src/Aspire.Hosting.Sdk/SDK/Sdk.targets @@ -19,17 +19,17 @@ - <_IsServiceApp Condition="'%(_IsServiceApp)' == '' and '%(IsAspireHostLibrary)' != 'true'">true + true - false - true - all + false + true + all diff --git a/src/Aspire.Hosting/ApplicationModel/ProjectResourceExtensions.cs b/src/Aspire.Hosting/ApplicationModel/ProjectResourceExtensions.cs index 7194cb385e..90913a33f8 100644 --- a/src/Aspire.Hosting/ApplicationModel/ProjectResourceExtensions.cs +++ b/src/Aspire.Hosting/ApplicationModel/ProjectResourceExtensions.cs @@ -34,19 +34,19 @@ internal static bool TryGetProjectWithPath(this DistributedApplicationModel mode // HACK: Until we use the DistributedApplicationModel as the source of truth, we will use // the name of the project resource as the DCP resource name. If this is a replica, it'll be projectname-{id}. .Where(p => p.Name == name || name.StartsWith(p.Name + "-")) - .SingleOrDefault(p => p.Annotations.OfType().FirstOrDefault()?.ProjectPath == path); + .SingleOrDefault(p => p.Annotations.OfType().FirstOrDefault()?.ProjectPath == path); return projectResource is not null; } /// - /// Gets the service metadata for the specified project resource. + /// Gets the project metadata for the specified project resource. /// /// The project resource. - /// The service metadata. - /// Thrown when the project resource doesn't have service metadata. - public static IServiceMetadata GetServiceMetadata(this ProjectResource projectResource) + /// The project metadata. + /// Thrown when the project resource doesn't have project metadata. + public static IProjectMetadata GetProjectMetadata(this ProjectResource projectResource) { - return projectResource.Annotations.OfType().Single(); + return projectResource.Annotations.OfType().Single(); } } diff --git a/src/Aspire.Hosting/Dcp/ApplicationExecutor.cs b/src/Aspire.Hosting/Dcp/ApplicationExecutor.cs index 71ff104804..fe4be2522d 100644 --- a/src/Aspire.Hosting/Dcp/ApplicationExecutor.cs +++ b/src/Aspire.Hosting/Dcp/ApplicationExecutor.cs @@ -391,7 +391,7 @@ private void PrepareProjectExecutables() foreach (var project in modelProjectResources) { - if (!project.TryGetLastAnnotation(out var projectMetadata)) + if (!project.TryGetLastAnnotation(out var projectMetadata)) { throw new InvalidOperationException("A project resource is missing required metadata"); // Should never happen. } diff --git a/src/Aspire.Hosting/Extensions/ProjectResourceBuilderExtensions.cs b/src/Aspire.Hosting/Extensions/ProjectResourceBuilderExtensions.cs index acb2c721a4..e25cc76117 100644 --- a/src/Aspire.Hosting/Extensions/ProjectResourceBuilderExtensions.cs +++ b/src/Aspire.Hosting/Extensions/ProjectResourceBuilderExtensions.cs @@ -22,7 +22,7 @@ public static class ProjectResourceBuilderExtensions /// The . /// The name of the resource. This name will be used for service discovery when referenced in a dependency. /// A reference to the . - public static IResourceBuilder AddProject(this IDistributedApplicationBuilder builder, string name) where TProject : IServiceMetadata, new() + public static IResourceBuilder AddProject(this IDistributedApplicationBuilder builder, string name) where TProject : IProjectMetadata, new() { var project = new ProjectResource(name); return builder.AddResource(project) @@ -45,7 +45,7 @@ public static IResourceBuilder AddProject(this IDistributedAppl return builder.AddResource(project) .WithProjectDefaults() - .WithAnnotation(new ServiceMetadata(projectPath)); + .WithAnnotation(new ProjectMetadata(projectPath)); } private static IResourceBuilder WithProjectDefaults(this IResourceBuilder builder) diff --git a/src/Aspire.Hosting/IServiceMetadata.cs b/src/Aspire.Hosting/IProjectMetadata.cs similarity index 66% rename from src/Aspire.Hosting/IServiceMetadata.cs rename to src/Aspire.Hosting/IProjectMetadata.cs index 6055f7178a..7c61fa9628 100644 --- a/src/Aspire.Hosting/IServiceMetadata.cs +++ b/src/Aspire.Hosting/IProjectMetadata.cs @@ -7,18 +7,18 @@ namespace Aspire.Hosting; /// -/// Represents metadata about a service. +/// Represents metadata about a project resource. /// -public interface IServiceMetadata : IResourceAnnotation +public interface IProjectMetadata : IResourceAnnotation { /// - /// Gets the fully-qualified path to the project containing the service. + /// Gets the fully-qualified path to the project. /// public string ProjectPath { get; } } [DebuggerDisplay("Type = {GetType().Name,nq}, ProjectPath = {ProjectPath}")] -internal class ServiceMetadata(string projectPath) : IServiceMetadata +internal class ProjectMetadata(string projectPath) : IProjectMetadata { public string ProjectPath { get; } = projectPath; } diff --git a/src/Aspire.Hosting/Properties/Resources.Designer.cs b/src/Aspire.Hosting/Properties/Resources.Designer.cs index 7d8b954a3a..3b0cf5887a 100644 --- a/src/Aspire.Hosting/Properties/Resources.Designer.cs +++ b/src/Aspire.Hosting/Properties/Resources.Designer.cs @@ -133,11 +133,11 @@ internal static string LaunchSettingsFileDoesNotContainProfileExceptionMessage { } /// - /// Looks up a localized string similar to Project does not contain service metadata.. + /// Looks up a localized string similar to Project does not contain project metadata.. /// - internal static string ProjectDoesNotContainServiceMetadataExceptionMessage { + internal static string ProjectDoesNotContainMetadataExceptionMessage { get { - return ResourceManager.GetString("ProjectDoesNotContainServiceMetadataExceptionMessage", resourceCulture); + return ResourceManager.GetString("ProjectDoesNotContainMetadataExceptionMessage", resourceCulture); } } diff --git a/src/Aspire.Hosting/Properties/Resources.resx b/src/Aspire.Hosting/Properties/Resources.resx index fea861feee..cde572dffe 100644 --- a/src/Aspire.Hosting/Properties/Resources.resx +++ b/src/Aspire.Hosting/Properties/Resources.resx @@ -141,8 +141,8 @@ Launch settings file does not contain '{0}' profile. - - Project does not contain service metadata. + + Project does not contain project metadata. Project file '{0}' was not found. diff --git a/src/Aspire.Hosting/Properties/xlf/Resources.cs.xlf b/src/Aspire.Hosting/Properties/xlf/Resources.cs.xlf index 2c2a197e72..72413b34d3 100644 --- a/src/Aspire.Hosting/Properties/xlf/Resources.cs.xlf +++ b/src/Aspire.Hosting/Properties/xlf/Resources.cs.xlf @@ -42,9 +42,9 @@ Launch settings file does not contain '{0}' profile. - - Project does not contain service metadata. - Project does not contain service metadata. + + Project does not contain project metadata. + Project does not contain project metadata. diff --git a/src/Aspire.Hosting/Properties/xlf/Resources.de.xlf b/src/Aspire.Hosting/Properties/xlf/Resources.de.xlf index 891f38c990..3835007318 100644 --- a/src/Aspire.Hosting/Properties/xlf/Resources.de.xlf +++ b/src/Aspire.Hosting/Properties/xlf/Resources.de.xlf @@ -42,9 +42,9 @@ Launch settings file does not contain '{0}' profile. - - Project does not contain service metadata. - Project does not contain service metadata. + + Project does not contain project metadata. + Project does not contain project metadata. diff --git a/src/Aspire.Hosting/Properties/xlf/Resources.es.xlf b/src/Aspire.Hosting/Properties/xlf/Resources.es.xlf index ca32b0ec72..bf9229c4fe 100644 --- a/src/Aspire.Hosting/Properties/xlf/Resources.es.xlf +++ b/src/Aspire.Hosting/Properties/xlf/Resources.es.xlf @@ -42,9 +42,9 @@ Launch settings file does not contain '{0}' profile. - - Project does not contain service metadata. - Project does not contain service metadata. + + Project does not contain project metadata. + Project does not contain project metadata. diff --git a/src/Aspire.Hosting/Properties/xlf/Resources.fr.xlf b/src/Aspire.Hosting/Properties/xlf/Resources.fr.xlf index 212bb9b435..90b2a1e25b 100644 --- a/src/Aspire.Hosting/Properties/xlf/Resources.fr.xlf +++ b/src/Aspire.Hosting/Properties/xlf/Resources.fr.xlf @@ -42,9 +42,9 @@ Launch settings file does not contain '{0}' profile. - - Project does not contain service metadata. - Project does not contain service metadata. + + Project does not contain project metadata. + Project does not contain project metadata. diff --git a/src/Aspire.Hosting/Properties/xlf/Resources.it.xlf b/src/Aspire.Hosting/Properties/xlf/Resources.it.xlf index 6c2257bdcb..527ba592af 100644 --- a/src/Aspire.Hosting/Properties/xlf/Resources.it.xlf +++ b/src/Aspire.Hosting/Properties/xlf/Resources.it.xlf @@ -42,9 +42,9 @@ Launch settings file does not contain '{0}' profile. - - Project does not contain service metadata. - Project does not contain service metadata. + + Project does not contain project metadata. + Project does not contain project metadata. diff --git a/src/Aspire.Hosting/Properties/xlf/Resources.ja.xlf b/src/Aspire.Hosting/Properties/xlf/Resources.ja.xlf index e6154249ef..24d1e5c89d 100644 --- a/src/Aspire.Hosting/Properties/xlf/Resources.ja.xlf +++ b/src/Aspire.Hosting/Properties/xlf/Resources.ja.xlf @@ -42,9 +42,9 @@ Launch settings file does not contain '{0}' profile. - - Project does not contain service metadata. - Project does not contain service metadata. + + Project does not contain project metadata. + Project does not contain project metadata. diff --git a/src/Aspire.Hosting/Properties/xlf/Resources.ko.xlf b/src/Aspire.Hosting/Properties/xlf/Resources.ko.xlf index b2acd8f61f..0e3d49b9a8 100644 --- a/src/Aspire.Hosting/Properties/xlf/Resources.ko.xlf +++ b/src/Aspire.Hosting/Properties/xlf/Resources.ko.xlf @@ -42,9 +42,9 @@ Launch settings file does not contain '{0}' profile. - - Project does not contain service metadata. - Project does not contain service metadata. + + Project does not contain project metadata. + Project does not contain project metadata. diff --git a/src/Aspire.Hosting/Properties/xlf/Resources.pl.xlf b/src/Aspire.Hosting/Properties/xlf/Resources.pl.xlf index dc0426ac09..e2eab2e2d3 100644 --- a/src/Aspire.Hosting/Properties/xlf/Resources.pl.xlf +++ b/src/Aspire.Hosting/Properties/xlf/Resources.pl.xlf @@ -42,9 +42,9 @@ Launch settings file does not contain '{0}' profile. - - Project does not contain service metadata. - Project does not contain service metadata. + + Project does not contain project metadata. + Project does not contain project metadata. diff --git a/src/Aspire.Hosting/Properties/xlf/Resources.pt-BR.xlf b/src/Aspire.Hosting/Properties/xlf/Resources.pt-BR.xlf index 31b5abb392..96dd929445 100644 --- a/src/Aspire.Hosting/Properties/xlf/Resources.pt-BR.xlf +++ b/src/Aspire.Hosting/Properties/xlf/Resources.pt-BR.xlf @@ -42,9 +42,9 @@ Launch settings file does not contain '{0}' profile. - - Project does not contain service metadata. - Project does not contain service metadata. + + Project does not contain project metadata. + Project does not contain project metadata. diff --git a/src/Aspire.Hosting/Properties/xlf/Resources.ru.xlf b/src/Aspire.Hosting/Properties/xlf/Resources.ru.xlf index 9f779cf271..286f2862c6 100644 --- a/src/Aspire.Hosting/Properties/xlf/Resources.ru.xlf +++ b/src/Aspire.Hosting/Properties/xlf/Resources.ru.xlf @@ -42,9 +42,9 @@ Launch settings file does not contain '{0}' profile. - - Project does not contain service metadata. - Project does not contain service metadata. + + Project does not contain project metadata. + Project does not contain project metadata. diff --git a/src/Aspire.Hosting/Properties/xlf/Resources.tr.xlf b/src/Aspire.Hosting/Properties/xlf/Resources.tr.xlf index 5dd5346491..a4a3001111 100644 --- a/src/Aspire.Hosting/Properties/xlf/Resources.tr.xlf +++ b/src/Aspire.Hosting/Properties/xlf/Resources.tr.xlf @@ -42,9 +42,9 @@ Launch settings file does not contain '{0}' profile. - - Project does not contain service metadata. - Project does not contain service metadata. + + Project does not contain project metadata. + Project does not contain project metadata. diff --git a/src/Aspire.Hosting/Properties/xlf/Resources.zh-Hans.xlf b/src/Aspire.Hosting/Properties/xlf/Resources.zh-Hans.xlf index a4b9465e2f..778229669a 100644 --- a/src/Aspire.Hosting/Properties/xlf/Resources.zh-Hans.xlf +++ b/src/Aspire.Hosting/Properties/xlf/Resources.zh-Hans.xlf @@ -42,9 +42,9 @@ Launch settings file does not contain '{0}' profile. - - Project does not contain service metadata. - Project does not contain service metadata. + + Project does not contain project metadata. + Project does not contain project metadata. diff --git a/src/Aspire.Hosting/Properties/xlf/Resources.zh-Hant.xlf b/src/Aspire.Hosting/Properties/xlf/Resources.zh-Hant.xlf index cd854b2c32..e790209152 100644 --- a/src/Aspire.Hosting/Properties/xlf/Resources.zh-Hant.xlf +++ b/src/Aspire.Hosting/Properties/xlf/Resources.zh-Hant.xlf @@ -42,9 +42,9 @@ Launch settings file does not contain '{0}' profile. - - Project does not contain service metadata. - Project does not contain service metadata. + + Project does not contain project metadata. + Project does not contain project metadata. diff --git a/src/Aspire.Hosting/Publishing/AutomaticManifestPublisherBindingInjectionHook.cs b/src/Aspire.Hosting/Publishing/AutomaticManifestPublisherBindingInjectionHook.cs index d32315cfca..fb3b6707df 100644 --- a/src/Aspire.Hosting/Publishing/AutomaticManifestPublisherBindingInjectionHook.cs +++ b/src/Aspire.Hosting/Publishing/AutomaticManifestPublisherBindingInjectionHook.cs @@ -14,9 +14,9 @@ internal sealed class AutomaticManifestPublisherBindingInjectionHook(IOptions(out var metadata)) + if (!project.TryGetLastAnnotation(out var metadata)) { - throw new DistributedApplicationException("Service metadata not found."); + throw new DistributedApplicationException("Project metadata not found."); } var relativePathToProjectFile = context.GetManifestRelativePath(metadata.ProjectPath); diff --git a/src/Aspire.Hosting/Utils/LaunchProfileExtensions.cs b/src/Aspire.Hosting/Utils/LaunchProfileExtensions.cs index ec8d8a0c56..ea8d17cf8d 100644 --- a/src/Aspire.Hosting/Utils/LaunchProfileExtensions.cs +++ b/src/Aspire.Hosting/Utils/LaunchProfileExtensions.cs @@ -14,12 +14,12 @@ internal static class LaunchProfileExtensions { internal static LaunchSettings? GetLaunchSettings(this ProjectResource projectResource) { - if (!projectResource.TryGetLastAnnotation(out var serviceMetadata)) + if (!projectResource.TryGetLastAnnotation(out var projectMetadata)) { - throw new DistributedApplicationException(Resources.ProjectDoesNotContainServiceMetadataExceptionMessage); + throw new DistributedApplicationException(Resources.ProjectDoesNotContainMetadataExceptionMessage); } - return serviceMetadata.GetLaunchSettings(); + return projectMetadata.GetLaunchSettings(); } internal static LaunchProfile? GetEffectiveLaunchProfile(this ProjectResource projectResource) @@ -40,15 +40,15 @@ internal static class LaunchProfileExtensions return found == true ? launchProfile : null; } - internal static LaunchSettings? GetLaunchSettings(this IServiceMetadata serviceMetadata) + internal static LaunchSettings? GetLaunchSettings(this IProjectMetadata projectMetadata) { - if (!File.Exists(serviceMetadata.ProjectPath)) + if (!File.Exists(projectMetadata.ProjectPath)) { - var message = string.Format(CultureInfo.InvariantCulture, Resources.ProjectFileNotFoundExceptionMessage, serviceMetadata.ProjectPath); + var message = string.Format(CultureInfo.InvariantCulture, Resources.ProjectFileNotFoundExceptionMessage, projectMetadata.ProjectPath); throw new DistributedApplicationException(message); } - var projectFileInfo = new FileInfo(serviceMetadata.ProjectPath); + var projectFileInfo = new FileInfo(projectMetadata.ProjectPath); var launchSettingsFilePath = projectFileInfo.DirectoryName switch { null => Path.Combine("Properties", "launchSettings.json"), diff --git a/src/Aspire.Hosting/build/Aspire.Hosting.targets b/src/Aspire.Hosting/build/Aspire.Hosting.targets index 0a477b4d8b..5ea6af88e9 100644 --- a/src/Aspire.Hosting/build/Aspire.Hosting.targets +++ b/src/Aspire.Hosting/build/Aspire.Hosting.targets @@ -12,66 +12,66 @@ - + - <_ServiceAppProject Include="@(ProjectReference->WithMetadataValue('_IsServiceApp', 'true'))" /> + <_AspireProjectResource Include="@(ProjectReference->WithMetadataValue('IsAspireProjectResource', 'true'))" /> - - + + - - $([System.IO.Path]::GetFileNameWithoutExtension(%(_ServiceAppProject.Identity)).Replace(".", "_").Replace("-","_").Replace(" ","_")) - $([System.String]::Copy(%(_ServiceAppProject.ServiceNameOverride)).Replace(".", "_").Replace("-","_").Replace(" ","_")) - $([System.IO.Path]::GetFullPath(%(_ServiceAppProject.Identity))) - + + $([System.IO.Path]::GetFileNameWithoutExtension(%(_AspireProjectResource.Identity)).Replace(".", "_").Replace("-","_").Replace(" ","_")) + $([System.String]::Copy(%(_AspireProjectResource.AspireProjectMetadataTypeName)).Replace(".", "_").Replace("-","_").Replace(" ","_")) + $([System.IO.Path]::GetFullPath(%(_AspireProjectResource.Identity))) + - + - + %(ClassName)%(ClassName) """]]>%(ProjectPath) - + - - - + + - + - + $([System.IO.Path]::GetFileNameWithoutExtension($(MSBuildProjectFile)).Replace(".", "_").Replace("-","_").Replace(" ","_")) $(MSBuildProjectDirectory) - + - + - + %(ClassName) """]]>%(ProjectPath) - + @@ -142,39 +142,39 @@ internal static class ]]>%(ClassName) - + - - + - - + + + Condition="'@(_AspireNonExecutableProjectResource)' != ''" + Text="'%(_AspireNonExecutableProjectResource.OriginalItemSpec)' is referenced by an Aspire Host project, but it is not an executable. Did you mean to set IsAspireProjectResource="false"?" /> - _CSharpWriteServiceMetadataSources;_CSharpAppHostProjectMetadataSources;_WarnOnUnsupportedLanguage;_ValidateAspireHostServiceReferences + _CSharpWriteProjectMetadataSources;_CSharpWriteHostProjectMetadataSources;_WarnOnUnsupportedLanguage;_ValidateAspireHostProjectResources - - + + diff --git a/tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj b/tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj index 44b49c5aa6..49bfa166b1 100644 --- a/tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj +++ b/tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj @@ -8,15 +8,15 @@ - - - + + + - - - - - + + + + + diff --git a/tests/Aspire.Hosting.Tests/MSBuildTests.cs b/tests/Aspire.Hosting.Tests/MSBuildTests.cs index cbae55957a..6e83b30748 100644 --- a/tests/Aspire.Hosting.Tests/MSBuildTests.cs +++ b/tests/Aspire.Hosting.Tests/MSBuildTests.cs @@ -56,7 +56,7 @@ public class Class1 - + @@ -72,7 +72,6 @@ public class Class1 true - <_SuppressImportAspireHostingOrchestrationTargets>true diff --git a/tests/Aspire.Hosting.Tests/ProjectResourceTests.cs b/tests/Aspire.Hosting.Tests/ProjectResourceTests.cs index 9f22bbd7a6..74d262fda8 100644 --- a/tests/Aspire.Hosting.Tests/ProjectResourceTests.cs +++ b/tests/Aspire.Hosting.Tests/ProjectResourceTests.cs @@ -25,7 +25,7 @@ public void AddProjectAddsEnvironmentVariablesAndServiceMetadata() Assert.Equal("projectName", resource.Name); Assert.Equal(5, resource.Annotations.Count); - var serviceMetadata = Assert.Single(resource.Annotations.OfType()); + var serviceMetadata = Assert.Single(resource.Annotations.OfType()); Assert.IsType(serviceMetadata); var annotations = resource.Annotations.OfType(); @@ -159,7 +159,7 @@ private static IDistributedApplicationBuilder CreateBuilder() return appBuilder; } - private sealed class TestProject : IServiceMetadata + private sealed class TestProject : IProjectMetadata { public string ProjectPath => "another-path"; } diff --git a/tests/testproject/TestProject.AppHost/Directory.Build.targets b/tests/testproject/TestProject.AppHost/Directory.Build.targets index 5bc3054c7b..112ac8875d 100644 --- a/tests/testproject/TestProject.AppHost/Directory.Build.targets +++ b/tests/testproject/TestProject.AppHost/Directory.Build.targets @@ -3,9 +3,6 @@ - - <_SuppressImportAspireHostingOrchestrationTargets>true - diff --git a/tests/testproject/TestProject.AppHost/TestProject.AppHost.csproj b/tests/testproject/TestProject.AppHost/TestProject.AppHost.csproj index 78ade1c1e5..4f385edcae 100644 --- a/tests/testproject/TestProject.AppHost/TestProject.AppHost.csproj +++ b/tests/testproject/TestProject.AppHost/TestProject.AppHost.csproj @@ -9,14 +9,14 @@ - - + + - - - - - + + + + + From 4686cd25c18de81d10c65ff15b5a6732e53af3fc Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Wed, 24 Jan 2024 15:00:24 -0600 Subject: [PATCH 13/13] Fix broken test --- tests/Aspire.Hosting.Tests/ProjectResourceTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Aspire.Hosting.Tests/ProjectResourceTests.cs b/tests/Aspire.Hosting.Tests/ProjectResourceTests.cs index 74d262fda8..4c304bd7a8 100644 --- a/tests/Aspire.Hosting.Tests/ProjectResourceTests.cs +++ b/tests/Aspire.Hosting.Tests/ProjectResourceTests.cs @@ -147,7 +147,7 @@ public void ProjectWithoutServiceMetadataFailsWithLaunchProfile() var projectResource = appBuilder.AddResource(project); var ex = Assert.Throws(() => projectResource.WithLaunchProfile("not-exist")); - Assert.Equal("Project does not contain service metadata.", ex.Message); + Assert.Equal("Project does not contain project metadata.", ex.Message); } private static IDistributedApplicationBuilder CreateBuilder()