Skip to content

Create a transport package for VS and VS authoring for analyzers #42451

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions src/Installer/core-sdk-tasks/GenerateRuntimeAnalyzersSWR.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// 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,
@"AspNetCoreAnalyzers",
@"SDK\AspNetCoreAnalyzers");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the target VS folder be something like DotNetSdk rather than just SDK?


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 = true)
{
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:\");
// 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)
{
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)

";
}
}
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>
1 change: 1 addition & 0 deletions src/Installer/redist-installer/redist-installer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<Import Project="targets\Crossgen.targets" />
<Import Project="targets\GenerateLayout.targets" />
<Import Project="targets\GenerateMSBuildExtensions.targets" />
<Import Project="targets\GenerateRuntimeAnalyzers.targets" />
<Import Project="targets\FileExtensions.targets" />
<Import Project="targets\GenerateArchives.targets" />
<Import Project="targets\GenerateMSIs.targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<UsingTask TaskName="ExtractArchiveToDirectory" AssemblyFile="$(CoreSdkTaskDll)" />
<UsingTask TaskName="GenerateDefaultRuntimeFrameworkVersion" AssemblyFile="$(CoreSdkTaskDll)" />
<UsingTask TaskName="GenerateMSBuildExtensionsSWR" AssemblyFile="$(CoreSdkTaskDll)" />
<UsingTask TaskName="GenerateRuntimeAnalyzersSWR" AssemblyFile="$(CoreSdkTaskDll)" />
<UsingTask TaskName="GenerateMsiVersionFromFullVersion" AssemblyFile="$(CoreSdkTaskDll)" />
<UsingTask TaskName="GenerateSdkRuntimeIdentifierChain" AssemblyFile="$(CoreSdkTaskDll)" />
<UsingTask TaskName="GetDependencyInfo" AssemblyFile="$(CoreSdkTaskDll)" />
Expand Down
26 changes: 26 additions & 0 deletions src/Installer/redist-installer/targets/GenerateMSIs.targets
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
<SdkMSBuildExtensionsNupkgFile>$(ArtifactsNonShippingPackagesDir)VS.Redist.Common.Net.Core.SDK.MSBuildExtensions.$(FullNugetVersion).nupkg</SdkMSBuildExtensionsNupkgFile>
<SdkMSBuildExtensionsSwrFile>$(ArtifactsNonShippingPackagesDir)VS.Redist.Common.Net.Core.SDK.MSBuildExtensions.swr</SdkMSBuildExtensionsSwrFile>

<SdkRuntimeAnalyzersNuspecFile>$(SdkPkgSourcesRootDirectory)/VS.Redist.Common.Net.Core.SDK.RuntimeAnalyzers.nuspec</SdkRuntimeAnalyzersNuspecFile>
<SdkRuntimeAnalyzersNupkgFile>$(ArtifactsNonShippingPackagesDir)VS.Redist.Common.Net.Core.SDK.RuntimeAnalyzers.$(FullNugetVersion).nupkg</SdkRuntimeAnalyzersNupkgFile>
<SdkRuntimeAnalyzersSwrFile>$(ArtifactsNonShippingPackagesDir)VS.Redist.Common.Net.Core.SDK.RuntimeAnalyzers.swr</SdkRuntimeAnalyzersSwrFile>

<VSTemplateLocatorLayoutPath>$(ArtifactsDir)bin/VSTemplateLocator/$(Configuration)</VSTemplateLocatorLayoutPath>
<VSTemplateLocatorNuspecFile>$(SdkPkgSourcesRootDirectory)/VS.Redist.Common.Net.Core.SDK.VSTemplateLocator.nuspec</VSTemplateLocatorNuspecFile>
<VSTemplateLocatorNupkgFile>$(ArtifactsNonShippingPackagesDir)VS.Redist.Common.Net.Core.SDK.VSTemplateLocator.$(FullNugetVersion).nupkg</VSTemplateLocatorNupkgFile>
Expand Down Expand Up @@ -497,6 +501,27 @@
'$(SdkMSBuildExtensionsNupkgFile)'" />
</Target>

<Target Name="GenerateRuntimeAnalyzersNupkg"
DependsOnTargets="GenerateLayout;MsiTargetsSetupInputOutputs"
Condition=" '$(OS)' == 'Windows_NT' And '$(Architecture)' == 'x64' "
Inputs="$(RuntimeAnalyzersLayoutDirectory)/**/*;
$(SdkRuntimeAnalyzersNuspecFile);
$(GenerateNupkgPowershellScript)"
Outputs="$(SdkRuntimeAnalyzersNupkgFile);$(SdkRuntimeAnalyzersSwrFile)">
<GenerateRuntimeAnalyzersSWR RuntimeAnalyzersLayoutDirectory="$(RuntimeAnalyzersLayoutDirectory)"
OutputFile="$(SdkRuntimeAnalyzersSwrFile)" />

<!-- Include the swr file in the nuget package for VS authoring -->
<Copy SourceFiles="$(SdkRuntimeAnalyzersSwrFile)" DestinationFolder="$(RuntimeAnalyzersLayoutDirectory)" />

<Exec Command="powershell -NoProfile -NoLogo $(GenerateNupkgPowershellScript) ^
'$(ArtifactsDir)' ^
'$(RuntimeAnalyzersLayoutDirectory.TrimEnd('\'))' ^
'$(FullNugetVersion)' ^
'$(SdkRuntimeAnalyzersNuspecFile)' ^
'$(SdkRuntimeAnalyzersNupkgFile)'" />
</Target>

<!--
This project references assets from multiple architectures, so it can't be built until we have a join point job that can pull assets from multiple legs.
https://github.com/dotnet/source-build/issues/4336
Expand Down Expand Up @@ -530,6 +555,7 @@
GenerateVSToolsNupkg;
GenerateVSToolsResolverNupkg;
GenerateSdkMSBuildExtensionsNupkg;
GenerateRuntimeAnalyzersNupkg;
GenerateVSTemplateLocatorNupkg"
Condition=" '$(OS)' == 'Windows_NT' and '$(Architecture)' != 'arm' " />

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project>

<PropertyGroup>
<RuntimeAnalyzersLayoutDirectory>$(ArtifactsBinDir)$(Configuration)\RuntimeAnalyzers</RuntimeAnalyzersLayoutDirectory>
</PropertyGroup>

</Project>
1 change: 1 addition & 0 deletions src/Layout/redist/redist.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<Import Project="targets\GenerateArchive.targets" />
<Import Project="targets\OverlaySdkOnLKG.targets" Condition="'$(DotNetBuild)' != 'true'" />
<Import Project="targets\MSBuildExtensions.targets" />
<Import Project="targets\RuntimeAnalyzers.targets" />

<ItemGroup>
<PackageReference Include="NuGet.Build.Tasks" />
Expand Down
7 changes: 7 additions & 0 deletions src/Layout/redist/targets/GenerateLayout.targets
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@

</Target>

<Target Name="PublishRuntimeAnalyzers"
DependsOnTargets="GenerateRuntimeAnalyzers"
BeforeTargets="Build">
<Copy SourceFiles="@(RuntimeAnalyzersContent)"
DestinationFiles="@(RuntimeAnalyzersContent->'$(ArtifactsBinDir)$(Configuration)\RuntimeAnalyzers\%(DeploymentSubpath)\%(RecursiveDir)%(Filename)%(Extension)')" />
</Target>

<Target Name="PublishNetSdks"
BeforeTargets="Build">
<ItemGroup>
Expand Down
3 changes: 0 additions & 3 deletions src/Layout/redist/targets/MSBuildExtensions.targets
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
<MSBuildExtensionsContent Include="$(MSBuildExtensionsSourceRoot)\msbuildExtensions-ver\**\*.*"
DeploymentSubpath="$(MSBuildExtensionsVersionSubfolder)/" />




</ItemGroup>

</Target>
Expand Down
23 changes: 23 additions & 0 deletions src/Layout/redist/targets/RuntimeAnalyzers.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project>

<PropertyGroup>
<RuntimeAnalyzersSourceRoot>$(ArtifactsBinDir)redist\$(Configuration)\dotnet\</RuntimeAnalyzersSourceRoot>
<NetCoreRuntimeAnalyzersSubPath>packs\Microsoft.NetCore.App.Ref\9.*\analyzers</NetCoreRuntimeAnalyzersSubPath>
<WindowsDesktopRuntimeAnalyzersSubPath>packs\Microsoft.WindowsDesktop.App.Ref\9.*\analyzers</WindowsDesktopRuntimeAnalyzersSubPath>
<AspNetCoreRuntimeAnalyzersSubPath>packs\Microsoft.AspNetCore.App.Ref\9.*\analyzers</AspNetCoreRuntimeAnalyzersSubPath>
<SDKAnalyzersSubPath>sdk\9.*\Sdks\Microsoft.NET.Sdk\Analyzers</SDKAnalyzersSubPath>
<WebSDKAnalyzersSubPath>sdk\9.*\Sdks\Microsoft.NET.Sdk.Web\Analyzers</WebSDKAnalyzersSubPath>
</PropertyGroup>

<Target Name="GenerateRuntimeAnalyzers">

<ItemGroup>
<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>
Loading