-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[9.0.3xx] Add analyzer redirecting VSIX #47021
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
jjonescz
merged 3 commits into
dotnet:release/9.0.3xx
from
jjonescz:analyzer-redirecting-9.0.3xx
Mar 10, 2025
Merged
Changes from all commits
Commits
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
134 changes: 134 additions & 0 deletions
134
src/Installer/core-sdk-tasks/GenerateRuntimeAnalyzersSWR.cs
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 |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| // Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| namespace Microsoft.DotNet.Cli.Build | ||
| { | ||
| public class GenerateRuntimeAnalyzersSWR : Task | ||
| { | ||
| [Required] | ||
| public string RuntimeAnalyzersLayoutDirectory { get; set; } | ||
|
|
||
| [Required] | ||
| public string OutputFile { get; set; } | ||
|
|
||
| public override bool Execute() | ||
| { | ||
| StringBuilder sb = new StringBuilder(SWR_HEADER); | ||
|
|
||
| // NOTE: Keep in sync with SdkAnalyzerAssemblyRedirector. | ||
| // This is intentionally short to avoid long path problems. | ||
| const string installDir = @"DotNetRuntimeAnalyzers"; | ||
|
|
||
| AddFolder(sb, | ||
| @"AnalyzerRedirecting", | ||
| @"Common7\IDE\CommonExtensions\Microsoft\AnalyzerRedirecting", | ||
| filesToInclude: | ||
| [ | ||
| "Microsoft.Net.Sdk.AnalyzerRedirecting.dll", | ||
| "Microsoft.Net.Sdk.AnalyzerRedirecting.pkgdef", | ||
| "extension.vsixmanifest", | ||
| ]); | ||
|
|
||
| AddFolder(sb, | ||
| @"AspNetCoreAnalyzers", | ||
| @$"{installDir}\AspNetCoreAnalyzers"); | ||
|
|
||
| AddFolder(sb, | ||
| @"NetCoreAnalyzers", | ||
| @$"{installDir}\NetCoreAnalyzers"); | ||
|
|
||
| AddFolder(sb, | ||
| @"WindowsDesktopAnalyzers", | ||
| @$"{installDir}\WindowsDesktopAnalyzers"); | ||
|
|
||
| AddFolder(sb, | ||
| @"SDKAnalyzers", | ||
| @$"{installDir}\SDKAnalyzers"); | ||
|
|
||
| AddFolder(sb, | ||
| @"WebSDKAnalyzers", | ||
| @$"{installDir}\WebSDKAnalyzers"); | ||
|
|
||
| File.WriteAllText(OutputFile, sb.ToString()); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| private void AddFolder(StringBuilder sb, string relativeSourcePath, string swrInstallDir, bool ngenAssemblies = false, IEnumerable<string> filesToInclude = null) | ||
| { | ||
| string sourceFolder = Path.Combine(RuntimeAnalyzersLayoutDirectory, relativeSourcePath); | ||
|
|
||
| // If files were specified explicitly, check that they exist. | ||
| if (filesToInclude != null) | ||
| { | ||
| foreach (var file in filesToInclude) | ||
| { | ||
| var path = Path.Combine(sourceFolder, file); | ||
| if (!File.Exists(path)) | ||
| { | ||
| throw new InvalidOperationException($"File not found: {path}"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| IEnumerable<string> files = filesToInclude ?? | ||
| Directory.GetFiles(sourceFolder) | ||
| .Where(static f => | ||
| { | ||
| var extension = Path.GetExtension(f); | ||
| return !extension.Equals(".pdb", StringComparison.OrdinalIgnoreCase) && | ||
| !extension.Equals(".swr", StringComparison.OrdinalIgnoreCase) && | ||
| !Path.GetFileName(f).Equals("_._"); | ||
| }); | ||
|
|
||
| if (files.Any()) | ||
| { | ||
| sb.Append(@"folder ""InstallDir:\"); | ||
| sb.Append(swrInstallDir); | ||
| sb.AppendLine(@"\"""); | ||
|
|
||
| foreach (var file in files) | ||
| { | ||
| var fileName = Path.GetFileName(file); | ||
|
|
||
| sb.Append(@" file source=""$(PkgVS_Redist_Common_Net_Core_SDK_RuntimeAnalyzers)\"); | ||
| sb.Append(Path.Combine(relativeSourcePath, fileName)); | ||
| sb.Append('"'); | ||
|
|
||
| if (ngenAssemblies && file.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| sb.Append(@" vs.file.ngenApplications=""[installDir]\Common7\IDE\vsn.exe"""); | ||
| } | ||
|
|
||
| sb.AppendLine(); | ||
| } | ||
|
|
||
| sb.AppendLine(); | ||
| } | ||
|
|
||
| // Don't go to sub-folders if the list of files was explicitly specified. | ||
| if (filesToInclude != null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| foreach (var subfolder in Directory.GetDirectories(sourceFolder)) | ||
| { | ||
| string subfolderName = Path.GetFileName(subfolder); | ||
| string newRelativeSourcePath = Path.Combine(relativeSourcePath, subfolderName); | ||
| string newSwrInstallDir = Path.Combine(swrInstallDir, subfolderName); | ||
|
|
||
| // Don't propagate ngenAssemblies to subdirectories. | ||
| AddFolder(sb, newRelativeSourcePath, newSwrInstallDir); | ||
| } | ||
| } | ||
|
|
||
| private static readonly string SWR_HEADER = @"use vs | ||
|
|
||
| package name=Microsoft.Net.Core.SDK.RuntimeAnalyzers | ||
| version=$(ProductsBuildVersion) | ||
| vs.package.internalRevision=$(PackageInternalRevision) | ||
|
|
||
| "; | ||
| } | ||
| } | ||
17 changes: 17 additions & 0 deletions
17
.../redist-installer/packaging/windows/VS.Redist.Common.Net.Core.SDK.RuntimeAnalyzers.nuspec
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 |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"> | ||
| <metadata> | ||
| <id>VS.Redist.Common.Net.Core.SDK.RuntimeAnalyzers</id> | ||
| <version>1.0.0</version> | ||
| <title>VS.Redist.Common.Net.Core.SDK.RuntimeAnalyzers</title> | ||
| <authors>Microsoft</authors> | ||
| <owners>Microsoft</owners> | ||
| <licenseUrl>https://www.microsoft.com/net/dotnet_library_license.htm</licenseUrl> | ||
| <projectUrl>https://github.com/dotnet/sdk</projectUrl> | ||
| <requireLicenseAcceptance>true</requireLicenseAcceptance> | ||
| <description>Analyzers and generators from the runtime and SDK for VS insertion</description> | ||
| <copyright>© Microsoft Corporation. All rights reserved.</copyright> | ||
| </metadata> | ||
| <files> | ||
| <file src="$PAYLOAD_FILES$\**\*" /> | ||
| </files> | ||
| </package> |
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
7 changes: 7 additions & 0 deletions
7
src/Installer/redist-installer/targets/GenerateRuntimeAnalyzers.targets
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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <Project> | ||
|
|
||
| <PropertyGroup> | ||
| <RuntimeAnalyzersLayoutDirectory>$(ArtifactsBinDir)$(Configuration)\RuntimeAnalyzers</RuntimeAnalyzersLayoutDirectory> | ||
| </PropertyGroup> | ||
|
|
||
| </Project> |
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 |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <Project> | ||
|
|
||
| <PropertyGroup> | ||
| <RuntimeAnalyzersSourceRoot>$(ArtifactsBinDir)redist\$(Configuration)\dotnet\</RuntimeAnalyzersSourceRoot> | ||
| <NetCoreRuntimeAnalyzersSubPath>packs\Microsoft.NetCore.App.Ref\*\analyzers</NetCoreRuntimeAnalyzersSubPath> | ||
| <WindowsDesktopRuntimeAnalyzersSubPath>packs\Microsoft.WindowsDesktop.App.Ref\*\analyzers</WindowsDesktopRuntimeAnalyzersSubPath> | ||
| <AspNetCoreRuntimeAnalyzersSubPath>packs\Microsoft.AspNetCore.App.Ref\*\analyzers</AspNetCoreRuntimeAnalyzersSubPath> | ||
| <SDKAnalyzersSubPath>sdk\*\Sdks\Microsoft.NET.Sdk\analyzers</SDKAnalyzersSubPath> | ||
| <WebSDKAnalyzersSubPath>sdk\*\Sdks\Microsoft.NET.Sdk.Web\analyzers</WebSDKAnalyzersSubPath> | ||
| </PropertyGroup> | ||
|
|
||
| <Target Name="GenerateRuntimeAnalyzers" AfterTargets="OverlaySdkOnLKG"> | ||
|
|
||
| <ItemGroup> | ||
| <RuntimeAnalyzersContent Include="$(ArtifactsBinDir)Microsoft.Net.Sdk.AnalyzerRedirecting\$(Configuration)\net472\**\*.*" DeploymentSubpath="AnalyzerRedirecting"/> | ||
| <RuntimeAnalyzersContent Include="$(RuntimeAnalyzersSourceRoot)$(NetCoreRuntimeAnalyzersSubPath)\**\*.*" DeploymentSubpath="NetCoreAnalyzers"/> | ||
| <RuntimeAnalyzersContent Include="$(RuntimeAnalyzersSourceRoot)$(WindowsDesktopRuntimeAnalyzersSubPath)\**\*.*" DeploymentSubpath="WindowsDesktopAnalyzers"/> | ||
| <RuntimeAnalyzersContent Include="$(RuntimeAnalyzersSourceRoot)$(AspNetCoreRuntimeAnalyzersSubPath)\**\*.*" DeploymentSubpath="AspNetCoreAnalyzers"/> | ||
| <RuntimeAnalyzersContent Include="$(RuntimeAnalyzersSourceRoot)$(SDKAnalyzersSubPath)\**\*.*" DeploymentSubpath="SDKAnalyzers"/> | ||
| <RuntimeAnalyzersContent Include="$(RuntimeAnalyzersSourceRoot)$(WebSDKAnalyzersSubPath)\**\*.*" DeploymentSubpath="WebSDKAnalyzers"/> | ||
| </ItemGroup> | ||
| </Target> | ||
|
|
||
| </Project> |
6 changes: 6 additions & 0 deletions
6
src/Microsoft.Net.Sdk.AnalyzerRedirecting/AnalyzerRedirectingPackage.cs
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 |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| using Microsoft.VisualStudio.Shell; | ||
|
|
||
| namespace Microsoft.Net.Sdk.AnalyzerRedirecting; | ||
|
|
||
| [Guid("ef89a321-14da-4de4-8f71-9bf1feea15aa")] | ||
| public sealed class AnalyzerRedirectingPackage : AsyncPackage; |
Oops, something went wrong.
Oops, something went wrong.
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.