-
Notifications
You must be signed in to change notification settings - Fork 933
Make ATS analyzer packaged in Aspire.Hosting and opt-in #15083
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b97ddde
Make ATS analyzer opt-in
sebastienros a34f7e4
Fix analyzer opt-in for RepoRoot consumers
sebastienros b879a0d
Merge remote-tracking branch 'upstream/release/13.2' into fix-15081-o…
eerhardt a70bc65
Split the ExportAnalyzer into its own analyzer library and include it…
eerhardt 4aeae2f
Revert previous changes.
eerhardt 0608489
Remove old tests
eerhardt d4e60b0
remove old test code
eerhardt e0245bf
Rename EnableAspireExportAnalyzers to EnableAspireIntegrationAnalyzers
eerhardt 2ba4177
Merge remote-tracking branch 'upstream/release/13.2' into fix-15081-o…
eerhardt bc21b88
Fix up for latest code.
eerhardt 9380e94
Merge remote-tracking branch 'origin/release/13.2' into fix-15081-opt…
sebastienros bade246
Centralize test Pkcs version
sebastienros 2b945c5
Fix Hosting analyzer packaging
sebastienros d3efc16
Remove Pkcs changes
eerhardt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -139,7 +139,12 @@ await Verify(new | |
| }); | ||
| } | ||
|
|
||
| private static void CreateDirectoryBuildFiles(string basePath, string repoRoot) | ||
| private static void CreateDirectoryBuildFiles( | ||
| string basePath, | ||
| string repoRoot, | ||
| bool enableAspireHostingAnalyzers = false, | ||
| bool useAnalyzerProjectReference = false, | ||
| string? analyzerAssemblyPath = null) | ||
| { | ||
| #if DEBUG | ||
| var config = "Debug"; | ||
|
|
@@ -151,7 +156,9 @@ private static void CreateDirectoryBuildFiles(string basePath, string repoRoot) | |
| $""" | ||
| <Project> | ||
| <PropertyGroup> | ||
| <RepoRoot>{repoRoot}\</RepoRoot> | ||
| <SkipAspireWorkloadManifest>true</SkipAspireWorkloadManifest> | ||
| <EnableAspireHostingAnalyzers>{enableAspireHostingAnalyzers.ToString().ToLowerInvariant()}</EnableAspireHostingAnalyzers> | ||
| </PropertyGroup> | ||
|
|
||
| <Import Project="{repoRoot}\src\Aspire.Hosting.AppHost\build\Aspire.Hosting.AppHost.props" /> | ||
|
|
@@ -162,8 +169,18 @@ private static void CreateDirectoryBuildFiles(string basePath, string repoRoot) | |
| <Project> | ||
| <PropertyGroup> | ||
| <_AspireTasksAssembly>{repoRoot}\artifacts\bin\Aspire.Hosting.Tasks\{config}\net8.0\Aspire.Hosting.Tasks.dll</_AspireTasksAssembly> | ||
| <_AspireHostingAnalyzerAssembly Condition="'$(EnableAspireHostingAnalyzers)' == 'true' and '{analyzerAssemblyPath}' != ''">{analyzerAssemblyPath}</_AspireHostingAnalyzerAssembly> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup Condition="'$(EnableAspireHostingAnalyzers)' == 'true' and '{useAnalyzerProjectReference.ToString().ToLowerInvariant()}' == 'true'"> | ||
| <ProjectReference Include="{repoRoot}\src\Aspire.Hosting.Analyzers\Aspire.Hosting.Analyzers.csproj" | ||
| IsAspireProjectResource="false" | ||
| PrivateAssets="all" | ||
| ReferenceOutputAssembly="false" | ||
| OutputItemType="Analyzer" | ||
| SetTargetFramework="TargetFramework=netstandard2.0" /> | ||
| </ItemGroup> | ||
|
|
||
| <Import Project="{repoRoot}\src\Aspire.Hosting.AppHost\build\Aspire.Hosting.AppHost.in.targets" /> | ||
| <Import Project="{repoRoot}\src\Aspire.AppHost.Sdk\SDK\Sdk.in.targets" /> | ||
| </Project> | ||
|
|
@@ -372,6 +389,194 @@ the Aspire.AppHost.SDK targets that will automatically add these references to p | |
| Assert.Contains("warning ASPIRE004", output); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void AspireHostingAnalyzersAreDisabledByDefault() | ||
|
Member
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. Is this enough or do we want a true nuget-based test? |
||
| { | ||
| var repoRoot = MSBuildUtils.GetRepoRoot(); | ||
| using var tempDirectory = new TestTempDirectory(); | ||
|
|
||
| var appHostDirectory = Path.Combine(tempDirectory.Path, "AppHost"); | ||
| Directory.CreateDirectory(appHostDirectory); | ||
|
|
||
| File.WriteAllText(Path.Combine(appHostDirectory, "AppHost.csproj"), | ||
| $""" | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <IsAspireHost>true</IsAspireHost> | ||
|
|
||
| <!-- | ||
| Test applications have their own way of referencing Aspire.Hosting.AppHost, as well as DCP and Dashboard, so we disable | ||
| the Aspire.AppHost.SDK targets that will automatically add these references to projects. | ||
| --> | ||
| <SkipAddAspireDefaultReferences Condition="'$(TestsRunningOutsideOfRepo)' != 'true'">true</SkipAddAspireDefaultReferences> | ||
| <AspireHostingSDKVersion>9.0.0</AspireHostingSDKVersion> | ||
| <_AspireUseTaskHostFactory>true</_AspireUseTaskHostFactory> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="{repoRoot}\src\Aspire.Hosting.AppHost\Aspire.Hosting.AppHost.csproj" IsAspireProjectResource="false" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
| """); | ||
|
|
||
| File.WriteAllText(Path.Combine(appHostDirectory, "AppHost.cs"), | ||
| """ | ||
| using Aspire.Hosting; | ||
|
|
||
| var builder = DistributedApplication.CreateBuilder(args); | ||
| builder.AddCustomResource(); | ||
| builder.Build().Run(); | ||
|
|
||
| public static class CustomResourceExtensions | ||
| { | ||
| public static IDistributedApplicationBuilder AddCustomResource(this IDistributedApplicationBuilder builder) | ||
| { | ||
| return builder; | ||
| } | ||
| } | ||
| """); | ||
|
|
||
| CreateDirectoryBuildFiles(appHostDirectory, repoRoot); | ||
|
|
||
| var output = BuildProject(appHostDirectory); | ||
|
|
||
| Assert.DoesNotContain("warning ASPIRE014", output); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void AspireHostingAnalyzersCanBeEnabledWithMsBuildProperty() | ||
| { | ||
| var repoRoot = MSBuildUtils.GetRepoRoot(); | ||
| using var tempDirectory = new TestTempDirectory(); | ||
|
|
||
| var appHostDirectory = Path.Combine(tempDirectory.Path, "AppHost"); | ||
| Directory.CreateDirectory(appHostDirectory); | ||
|
|
||
| File.WriteAllText(Path.Combine(appHostDirectory, "AppHost.csproj"), | ||
| $""" | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <IsAspireHost>true</IsAspireHost> | ||
|
|
||
| <!-- | ||
| Test applications have their own way of referencing Aspire.Hosting.AppHost, as well as DCP and Dashboard, so we disable | ||
| the Aspire.AppHost.SDK targets that will automatically add these references to projects. | ||
| --> | ||
| <SkipAddAspireDefaultReferences Condition="'$(TestsRunningOutsideOfRepo)' != 'true'">true</SkipAddAspireDefaultReferences> | ||
| <AspireHostingSDKVersion>9.0.0</AspireHostingSDKVersion> | ||
| <_AspireUseTaskHostFactory>true</_AspireUseTaskHostFactory> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="{repoRoot}\src\Aspire.Hosting.AppHost\Aspire.Hosting.AppHost.csproj" IsAspireProjectResource="false" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
| """); | ||
|
|
||
| File.WriteAllText(Path.Combine(appHostDirectory, "AppHost.cs"), | ||
| """ | ||
| using Aspire.Hosting; | ||
|
|
||
| var builder = DistributedApplication.CreateBuilder(args); | ||
| builder.AddCustomResource(); | ||
| builder.Build().Run(); | ||
|
|
||
| public static class CustomResourceExtensions | ||
| { | ||
| public static IDistributedApplicationBuilder AddCustomResource(this IDistributedApplicationBuilder builder) | ||
| { | ||
| return builder; | ||
| } | ||
| } | ||
| """); | ||
|
|
||
| CreateDirectoryBuildFiles(appHostDirectory, repoRoot, enableAspireHostingAnalyzers: true, useAnalyzerProjectReference: true); | ||
|
|
||
| var output = BuildProject(appHostDirectory); | ||
|
|
||
| Assert.Contains("warning ASPIRE014", output); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void AspireHostingAnalyzersCanBeEnabledWhenRepoRootIsSet() | ||
| { | ||
| var repoRoot = MSBuildUtils.GetRepoRoot(); | ||
| using var tempDirectory = new TestTempDirectory(); | ||
|
|
||
| #if DEBUG | ||
| var config = "Debug"; | ||
| #else | ||
| var config = "Release"; | ||
| #endif | ||
|
|
||
| var appHostDirectory = Path.Combine(tempDirectory.Path, "AppHost"); | ||
| Directory.CreateDirectory(appHostDirectory); | ||
|
|
||
| File.WriteAllText(Path.Combine(appHostDirectory, "AppHost.csproj"), | ||
| $""" | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <IsAspireHost>true</IsAspireHost> | ||
|
|
||
| <!-- | ||
| Test applications have their own way of referencing Aspire.Hosting.AppHost, as well as DCP and Dashboard, so we disable | ||
| the Aspire.AppHost.SDK targets that will automatically add these references to projects. | ||
| --> | ||
| <SkipAddAspireDefaultReferences Condition="'$(TestsRunningOutsideOfRepo)' != 'true'">true</SkipAddAspireDefaultReferences> | ||
| <AspireHostingSDKVersion>9.0.0</AspireHostingSDKVersion> | ||
| <_AspireUseTaskHostFactory>true</_AspireUseTaskHostFactory> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="{repoRoot}\src\Aspire.Hosting.AppHost\Aspire.Hosting.AppHost.csproj" IsAspireProjectResource="false" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
| """); | ||
|
|
||
| File.WriteAllText(Path.Combine(appHostDirectory, "AppHost.cs"), | ||
| """ | ||
| using Aspire.Hosting; | ||
|
|
||
| var builder = DistributedApplication.CreateBuilder(args); | ||
| builder.AddCustomResource(); | ||
| builder.Build().Run(); | ||
|
|
||
| public static class CustomResourceExtensions | ||
| { | ||
| public static IDistributedApplicationBuilder AddCustomResource(this IDistributedApplicationBuilder builder) | ||
| { | ||
| return builder; | ||
| } | ||
| } | ||
| """); | ||
|
|
||
| var analyzerAssemblyPath = Path.Combine(repoRoot, "artifacts", "bin", "Aspire.Hosting.Analyzers", config, "netstandard2.0", "Aspire.Hosting.Analyzers.dll"); | ||
|
|
||
| CreateDirectoryBuildFiles(appHostDirectory, repoRoot, enableAspireHostingAnalyzers: true, analyzerAssemblyPath: analyzerAssemblyPath); | ||
|
|
||
| var output = BuildProject(appHostDirectory); | ||
|
|
||
| Assert.Contains("warning ASPIRE014", output); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Tests that when GenerateAssemblyInfo is set to false, a build error is emitted. | ||
| /// </summary> | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.