From 465f6ebe17c7b98c8381b273f53657c601b57ceb Mon Sep 17 00:00:00 2001 From: Marc Paine Date: Fri, 26 Jul 2024 16:07:02 -0700 Subject: [PATCH 1/2] Creation of a Analyzers nupkg for VS insertion. There are 5 analyzers we want to include. Other teams are investigating a potentially mapping and final location. This is just a placeholder to generate the package. This is also WIP as I don't have the VS side of things finding the right files yet. --- .../GenerateRuntimeAnalyzersSWR.cs | 75 +++++++++++++++++++ ...ommon.Net.Core.SDK.RuntimeAnalyzers.nuspec | 17 +++++ .../redist-installer/redist-installer.csproj | 1 + .../targets/BuildCoreSdkTasks.targets | 1 + .../targets/GenerateMSIs.targets | 26 +++++++ .../targets/GenerateRuntimeAnalyzers.targets | 22 ++++++ src/Layout/redist/redist.csproj | 1 + .../redist/targets/GenerateLayout.targets | 7 ++ .../redist/targets/MSBuildExtensions.targets | 3 - .../redist/targets/RuntimeAnalyzers.targets | 24 ++++++ 10 files changed, 174 insertions(+), 3 deletions(-) create mode 100644 src/Installer/core-sdk-tasks/GenerateRuntimeAnalyzersSWR.cs create mode 100644 src/Installer/redist-installer/packaging/windows/VS.Redist.Common.Net.Core.SDK.RuntimeAnalyzers.nuspec create mode 100644 src/Installer/redist-installer/targets/GenerateRuntimeAnalyzers.targets create mode 100644 src/Layout/redist/targets/RuntimeAnalyzers.targets diff --git a/src/Installer/core-sdk-tasks/GenerateRuntimeAnalyzersSWR.cs b/src/Installer/core-sdk-tasks/GenerateRuntimeAnalyzersSWR.cs new file mode 100644 index 000000000000..d69360fb98f2 --- /dev/null +++ b/src/Installer/core-sdk-tasks/GenerateRuntimeAnalyzersSWR.cs @@ -0,0 +1,75 @@ +// 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); + + AddFolder(sb, + @"RuntimeAnalyzers", + @"MSBuild"); + + File.WriteAllText(OutputFile, sb.ToString()); + + return true; + } + + private void AddFolder(StringBuilder sb, string relativeSourcePath, string swrInstallDir, bool ngenAssemblies = false) + { + string sourceFolder = Path.Combine(RuntimeAnalyzersLayoutDirectory, relativeSourcePath); + var files = Directory.GetFiles(sourceFolder) + .Where(f => !Path.GetExtension(f).Equals(".pdb", StringComparison.OrdinalIgnoreCase) && !Path.GetExtension(f).Equals(".swr", StringComparison.OrdinalIgnoreCase)) + .ToList(); + if (files.Any(f => !Path.GetFileName(f).Equals("_._"))) + { + sb.Append(@"folder ""InstallDir:\"); + sb.Append(swrInstallDir); + sb.AppendLine(@"\"""); + + foreach (var file in files) + { + sb.Append(@" file source=""$(PkgVS_Redist_Common_Net_Core_SDK_RuntimeAnalyzers)\"); + sb.Append(Path.Combine(relativeSourcePath, Path.GetFileName(file))); + sb.Append('"'); + + if (ngenAssemblies && file.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) + { + sb.Append(@" vs.file.ngenApplications=""[installDir]\Common7\IDE\vsn.exe"""); + } + + sb.AppendLine(); + } + + sb.AppendLine(); + } + + 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); + } + } + + readonly string SWR_HEADER = @"use vs + +package name=Microsoft.Net.Core.SDK.RuntimeAnalyzers + version=$(ProductsBuildVersion) + vs.package.internalRevision=$(PackageInternalRevision) + +"; + } +} diff --git a/src/Installer/redist-installer/packaging/windows/VS.Redist.Common.Net.Core.SDK.RuntimeAnalyzers.nuspec b/src/Installer/redist-installer/packaging/windows/VS.Redist.Common.Net.Core.SDK.RuntimeAnalyzers.nuspec new file mode 100644 index 000000000000..b3a7b71cd697 --- /dev/null +++ b/src/Installer/redist-installer/packaging/windows/VS.Redist.Common.Net.Core.SDK.RuntimeAnalyzers.nuspec @@ -0,0 +1,17 @@ + + + VS.Redist.Common.Net.Core.SDK.RuntimeAnalyzers + 1.0.0 + VS.Redist.Common.Net.Core.SDK.RuntimeAnalyzers + Microsoft + Microsoft + https://www.microsoft.com/net/dotnet_library_license.htm + https://github.com/dotnet/sdk + true + Analyzers and generators from the runtime and SDK for VS insertion + © Microsoft Corporation. All rights reserved. + + + + + diff --git a/src/Installer/redist-installer/redist-installer.csproj b/src/Installer/redist-installer/redist-installer.csproj index 311563a2d562..6f16be86da32 100644 --- a/src/Installer/redist-installer/redist-installer.csproj +++ b/src/Installer/redist-installer/redist-installer.csproj @@ -43,6 +43,7 @@ + diff --git a/src/Installer/redist-installer/targets/BuildCoreSdkTasks.targets b/src/Installer/redist-installer/targets/BuildCoreSdkTasks.targets index ce51df4b4116..9927e46d9799 100644 --- a/src/Installer/redist-installer/targets/BuildCoreSdkTasks.targets +++ b/src/Installer/redist-installer/targets/BuildCoreSdkTasks.targets @@ -32,6 +32,7 @@ + diff --git a/src/Installer/redist-installer/targets/GenerateMSIs.targets b/src/Installer/redist-installer/targets/GenerateMSIs.targets index c3809e3e221d..8e093f214f60 100644 --- a/src/Installer/redist-installer/targets/GenerateMSIs.targets +++ b/src/Installer/redist-installer/targets/GenerateMSIs.targets @@ -37,6 +37,10 @@ $(ArtifactsNonShippingPackagesDir)VS.Redist.Common.Net.Core.SDK.MSBuildExtensions.$(FullNugetVersion).nupkg $(ArtifactsNonShippingPackagesDir)VS.Redist.Common.Net.Core.SDK.MSBuildExtensions.swr + $(SdkPkgSourcesRootDirectory)/VS.Redist.Common.Net.Core.SDK.RuntimeAnalyzers.nuspec + $(ArtifactsNonShippingPackagesDir)VS.Redist.Common.Net.Core.SDK.RuntimeAnalyzers.$(FullNugetVersion).nupkg + $(ArtifactsNonShippingPackagesDir)VS.Redist.Common.Net.Core.SDK.RuntimeAnalyzers.swr + $(ArtifactsDir)bin/VSTemplateLocator/$(Configuration) $(SdkPkgSourcesRootDirectory)/VS.Redist.Common.Net.Core.SDK.VSTemplateLocator.nuspec $(ArtifactsNonShippingPackagesDir)VS.Redist.Common.Net.Core.SDK.VSTemplateLocator.$(FullNugetVersion).nupkg @@ -497,6 +501,27 @@ '$(SdkMSBuildExtensionsNupkgFile)'" /> + + + + + + + + + + + + + $(RuntimeAnalyzersLayoutDirectory)/%(RecursiveDir)%(Filename)%(Extension) + + + + + + + diff --git a/src/Layout/redist/redist.csproj b/src/Layout/redist/redist.csproj index d0dce1a55d39..335aa9aec609 100644 --- a/src/Layout/redist/redist.csproj +++ b/src/Layout/redist/redist.csproj @@ -27,6 +27,7 @@ + diff --git a/src/Layout/redist/targets/GenerateLayout.targets b/src/Layout/redist/targets/GenerateLayout.targets index e7cd9e392c3e..a7209a39b680 100644 --- a/src/Layout/redist/targets/GenerateLayout.targets +++ b/src/Layout/redist/targets/GenerateLayout.targets @@ -130,6 +130,13 @@ + + + + diff --git a/src/Layout/redist/targets/MSBuildExtensions.targets b/src/Layout/redist/targets/MSBuildExtensions.targets index 41bcd4be1172..e68d8d72a0b9 100644 --- a/src/Layout/redist/targets/MSBuildExtensions.targets +++ b/src/Layout/redist/targets/MSBuildExtensions.targets @@ -22,9 +22,6 @@ - - - diff --git a/src/Layout/redist/targets/RuntimeAnalyzers.targets b/src/Layout/redist/targets/RuntimeAnalyzers.targets new file mode 100644 index 000000000000..ef4277060fbe --- /dev/null +++ b/src/Layout/redist/targets/RuntimeAnalyzers.targets @@ -0,0 +1,24 @@ + + + + $(ArtifactsBinDir)redist\$(Configuration)\dotnet\ + packs\Microsoft.NetCore.App.Ref\9.*\analyzers + packs\Microsoft.WindowsDesktop.App.Ref\9.*\analyzers + packs\Microsoft.AspNetCore.App.Ref\9.*\analyzers + sdk\9.*\Sdks\Microsoft.NET.Sdk\Analyzers + sdk\9.*\Sdks\Microsoft.NET.Sdk.Web\Analyzers + + + + + + + + + + + + + + + From 6256806ded42709c911976e1ba5d2f23b6ebccd3 Mon Sep 17 00:00:00 2001 From: Marc Paine Date: Mon, 29 Jul 2024 16:49:47 -0700 Subject: [PATCH 2/2] Update the redist-installer side of the change Put the analyzers in the SDK folder in a separate sub-folder for each. --- .../GenerateRuntimeAnalyzersSWR.cs | 34 ++++++++++++++++--- .../targets/GenerateMSIs.targets | 2 +- .../targets/GenerateRuntimeAnalyzers.targets | 17 +--------- .../redist/targets/GenerateLayout.targets | 2 +- .../redist/targets/RuntimeAnalyzers.targets | 1 - 5 files changed, 33 insertions(+), 23 deletions(-) diff --git a/src/Installer/core-sdk-tasks/GenerateRuntimeAnalyzersSWR.cs b/src/Installer/core-sdk-tasks/GenerateRuntimeAnalyzersSWR.cs index d69360fb98f2..aa36e3e2e115 100644 --- a/src/Installer/core-sdk-tasks/GenerateRuntimeAnalyzersSWR.cs +++ b/src/Installer/core-sdk-tasks/GenerateRuntimeAnalyzersSWR.cs @@ -16,15 +16,31 @@ public override bool Execute() StringBuilder sb = new StringBuilder(SWR_HEADER); AddFolder(sb, - @"RuntimeAnalyzers", - @"MSBuild"); + @"AspNetCoreAnalyzers", + @"SDK\AspNetCoreAnalyzers"); + + AddFolder(sb, + @"NetCoreAnalyzers", + @"SDK\NetCoreAnalyzers"); + + AddFolder(sb, + @"WindowsDesktopAnalyzers", + @"SDK\WindowsDesktopAnalyzers"); + + AddFolder(sb, + @"SDKAnalyzers", + @"SDK\SDKAnalyzers"); + + AddFolder(sb, + @"WebSDKAnalyzers", + @"SDK\WebSDKAnalyzers"); File.WriteAllText(OutputFile, sb.ToString()); return true; } - private void AddFolder(StringBuilder sb, string relativeSourcePath, string swrInstallDir, bool ngenAssemblies = false) + private void AddFolder(StringBuilder sb, string relativeSourcePath, string swrInstallDir, bool ngenAssemblies = true) { string sourceFolder = Path.Combine(RuntimeAnalyzersLayoutDirectory, relativeSourcePath); var files = Directory.GetFiles(sourceFolder) @@ -33,7 +49,17 @@ private void AddFolder(StringBuilder sb, string relativeSourcePath, string swrIn if (files.Any(f => !Path.GetFileName(f).Equals("_._"))) { sb.Append(@"folder ""InstallDir:\"); - sb.Append(swrInstallDir); + // remove the version number and everything until we get to the real analyzers folder + Console.WriteLine(swrInstallDir); + + var startIndex = swrInstallDir.IndexOf("analyzers", StringComparison.OrdinalIgnoreCase); + var endIndex = swrInstallDir.IndexOf("analyzers", startIndex + 1, StringComparison.OrdinalIgnoreCase); + var tempinstalldir = swrInstallDir; + if (startIndex >= 0 && endIndex >= 0) + { + tempinstalldir = swrInstallDir.Remove(startIndex + 9, endIndex - startIndex ); + } + sb.Append(tempinstalldir); sb.AppendLine(@"\"""); foreach (var file in files) diff --git a/src/Installer/redist-installer/targets/GenerateMSIs.targets b/src/Installer/redist-installer/targets/GenerateMSIs.targets index 8e093f214f60..c7114062db33 100644 --- a/src/Installer/redist-installer/targets/GenerateMSIs.targets +++ b/src/Installer/redist-installer/targets/GenerateMSIs.targets @@ -502,7 +502,7 @@ - - - - - - $(RuntimeAnalyzersLayoutDirectory)/%(RecursiveDir)%(Filename)%(Extension) - - - - - - diff --git a/src/Layout/redist/targets/GenerateLayout.targets b/src/Layout/redist/targets/GenerateLayout.targets index a7209a39b680..1981da9ef632 100644 --- a/src/Layout/redist/targets/GenerateLayout.targets +++ b/src/Layout/redist/targets/GenerateLayout.targets @@ -134,7 +134,7 @@ DependsOnTargets="GenerateRuntimeAnalyzers" BeforeTargets="Build"> + DestinationFiles="@(RuntimeAnalyzersContent->'$(ArtifactsBinDir)$(Configuration)\RuntimeAnalyzers\%(DeploymentSubpath)\%(RecursiveDir)%(Filename)%(Extension)')" /> -