Skip to content
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

ApiCompat: Add ValidateAssemblies msbuild task and add global tool #26616

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
cf4a93c
Resource updates
ViktorHofer Jul 13, 2022
0e8678c
Solution file updates
ViktorHofer Jul 13, 2022
da1a4e3
msbuild targets file updates
ViktorHofer Jul 13, 2022
6310adb
Project file updates
ViktorHofer Jul 13, 2022
b10739b
Frontend code (task & console + shared)
ViktorHofer Jul 13, 2022
8a26cc4
ApiCompatibility layer updates
ViktorHofer Jul 13, 2022
8c868a6
PackageValidation layer updates
ViktorHofer Jul 13, 2022
1a93640
Test updates and additions
ViktorHofer Jul 13, 2022
2c4b7a3
Update CODEOWNERS file
ViktorHofer Jul 13, 2022
40f5d74
Adjust namespaces
ViktorHofer Jul 21, 2022
0c6c651
PR feedback for RoslynResolver
ViktorHofer Jul 21, 2022
4640173
Merge remote-tracking branch 'upstream/main' into BigRefactoringOfCom…
ViktorHofer Jul 21, 2022
0f991d9
Fix build failure and address PR feedback
ViktorHofer Jul 21, 2022
0b977a6
Rename helper to SuppressionFileHelper
ViktorHofer Jul 28, 2022
b539c0e
Default RunApiCompat to true in ValidatePackage task
ViktorHofer Jul 28, 2022
c278364
Refine RoslynResolver usage
ViktorHofer Jul 28, 2022
6c64a49
Update documentation
ViktorHofer Jul 28, 2022
d83c3a8
Use windows directory separators chars
ViktorHofer Jul 28, 2022
4f3c499
Fix build break
ViktorHofer Jul 28, 2022
5d2730e
Make RoslynAssembliesPath non required
ViktorHofer Jul 29, 2022
eaa817b
Add doc to keep parameters in sync in frontends
ViktorHofer Jul 29, 2022
7c90903
nit style clean-up
ViktorHofer Jul 29, 2022
82db8dc
Add regex match timeout and add a test for it
ViktorHofer Jul 29, 2022
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
5 changes: 3 additions & 2 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,6 @@
# Compatibility tools owned by runtime team
# Area-Compatibility
/src/Compatibility/ @ericstj @dotnet/area-infrastructure-libraries @joperezr
/src/Tests/Microsoft.DotNet.ApiCompatibility.Tests/ @ericstj @dotnet/area-infrastructure-libraries @joperezr
/src/Tests/Microsoft.DotNet.PackageValidation.Tests/ @ericstj @dotnet/area-infrastructure-libraries @joperezr
/src/Tests/Microsoft.DotNet.ApiCompatibility*/ @ericstj @dotnet/area-infrastructure-libraries @joperezr
/src/Tests/Microsoft.DotNet.ApiCompat*/ @ericstj @dotnet/area-infrastructure-libraries @joperezr
/src/Tests/Microsoft.DotNet.PackageValidation*/ @ericstj @dotnet/area-infrastructure-libraries @joperezr
1 change: 1 addition & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
</PropertyGroup>
<!-- Production Dependencies -->
<PropertyGroup>
<JabVersion>0.8.0</JabVersion>
<MicrosoftBuildVersion>15.4.8</MicrosoftBuildVersion>
<MicrosoftBuildFrameworkVersion>15.4.8</MicrosoftBuildFrameworkVersion>
<MicrosoftBuildUtilitiesCoreVersion>15.4.8</MicrosoftBuildUtilitiesCoreVersion>
Expand Down
51 changes: 33 additions & 18 deletions sdk.sln
Original file line number Diff line number Diff line change
Expand Up @@ -359,16 +359,20 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.PackageVal
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.DotNetDeltaApplier.Tests", "src\Tests\Microsoft.Extensions.DotNetDeltaApplier.Tests\Microsoft.Extensions.DotNetDeltaApplier.Tests.csproj", "{FAAC2E23-A460-40FE-9207-C10EEE5A6A07}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.Compatibility", "src\Compatibility\Microsoft.DotNet.Compatibility\Microsoft.DotNet.Compatibility.csproj", "{87AE3308-8CCB-4383-8F51-C5061E348C36}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.NET.Sdk.BlazorWebAssembly.AoT.Tests", "src\Tests\Microsoft.NET.Sdk.BlazorWebAssembly.AoT.Tests\Microsoft.NET.Sdk.BlazorWebAssembly.AoT.Tests.csproj", "{920F6448-C2D0-4B01-AC25-16214C5A6006}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.Compatibility.Console", "src\Compatibility\Microsoft.DotNet.Compatibility.Console\Microsoft.DotNet.Compatibility.Console.csproj", "{9D08CED8-02CC-4566-A3B7-3434D205F0A2}"
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Microsoft.DotNet.ApiCompat.Shared", "src\Compatibility\Microsoft.DotNet.ApiCompat.Shared\Microsoft.DotNet.ApiCompat.Shared.shproj", "{9D36039F-D0A1-462F-85B4-81763C6B02CB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.ApiCompat.Task", "src\Compatibility\Microsoft.DotNet.ApiCompat.Task\Microsoft.DotNet.ApiCompat.Task.csproj", "{03C5A84A-982B-4F38-AC73-AB832C645C4A}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Microsoft.DotNet.Compatibility.Shared", "src\Compatibility\Microsoft.DotNet.Compatibility.Shared\Microsoft.DotNet.Compatibility.Shared.shproj", "{68E743E6-5D4B-4CD4-941A-07285032451F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.ApiCompat.Tool", "src\Compatibility\Microsoft.DotNet.ApiCompat.Tool\Microsoft.DotNet.ApiCompat.Tool.csproj", "{0A3C9AFD-F6E6-4A5D-83FB-93BF66732696}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "trustedroots.Tests", "src\Tests\trustedroots.Tests\trustedroots.Tests.csproj", "{08A18C0B-8985-49EE-AC80-EFEEDF18BCC5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.ApiCompat.IntegrationTests", "src\Tests\Microsoft.DotNet.ApiCompat.IntegrationTests\Microsoft.DotNet.ApiCompat.IntegrationTests.csproj", "{AE43BEC0-4BB7-42E1-B2B7-60A36092C61A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.ApiCompat.Tests", "src\Tests\Microsoft.DotNet.ApiCompat.Tests\Microsoft.DotNet.ApiCompat.Tests.csproj", "{A9103B98-D888-4260-8A05-FA36F640698A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -667,22 +671,30 @@ Global
{FAAC2E23-A460-40FE-9207-C10EEE5A6A07}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FAAC2E23-A460-40FE-9207-C10EEE5A6A07}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FAAC2E23-A460-40FE-9207-C10EEE5A6A07}.Release|Any CPU.Build.0 = Release|Any CPU
{87AE3308-8CCB-4383-8F51-C5061E348C36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{87AE3308-8CCB-4383-8F51-C5061E348C36}.Debug|Any CPU.Build.0 = Debug|Any CPU
{87AE3308-8CCB-4383-8F51-C5061E348C36}.Release|Any CPU.ActiveCfg = Release|Any CPU
{87AE3308-8CCB-4383-8F51-C5061E348C36}.Release|Any CPU.Build.0 = Release|Any CPU
{920F6448-C2D0-4B01-AC25-16214C5A6006}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{920F6448-C2D0-4B01-AC25-16214C5A6006}.Debug|Any CPU.Build.0 = Debug|Any CPU
{920F6448-C2D0-4B01-AC25-16214C5A6006}.Release|Any CPU.ActiveCfg = Release|Any CPU
{920F6448-C2D0-4B01-AC25-16214C5A6006}.Release|Any CPU.Build.0 = Release|Any CPU
{9D08CED8-02CC-4566-A3B7-3434D205F0A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9D08CED8-02CC-4566-A3B7-3434D205F0A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D08CED8-02CC-4566-A3B7-3434D205F0A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D08CED8-02CC-4566-A3B7-3434D205F0A2}.Release|Any CPU.Build.0 = Release|Any CPU
{03C5A84A-982B-4F38-AC73-AB832C645C4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{03C5A84A-982B-4F38-AC73-AB832C645C4A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{03C5A84A-982B-4F38-AC73-AB832C645C4A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{03C5A84A-982B-4F38-AC73-AB832C645C4A}.Release|Any CPU.Build.0 = Release|Any CPU
{0A3C9AFD-F6E6-4A5D-83FB-93BF66732696}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0A3C9AFD-F6E6-4A5D-83FB-93BF66732696}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A3C9AFD-F6E6-4A5D-83FB-93BF66732696}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0A3C9AFD-F6E6-4A5D-83FB-93BF66732696}.Release|Any CPU.Build.0 = Release|Any CPU
{08A18C0B-8985-49EE-AC80-EFEEDF18BCC5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{08A18C0B-8985-49EE-AC80-EFEEDF18BCC5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{08A18C0B-8985-49EE-AC80-EFEEDF18BCC5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{08A18C0B-8985-49EE-AC80-EFEEDF18BCC5}.Release|Any CPU.Build.0 = Release|Any CPU
{AE43BEC0-4BB7-42E1-B2B7-60A36092C61A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AE43BEC0-4BB7-42E1-B2B7-60A36092C61A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AE43BEC0-4BB7-42E1-B2B7-60A36092C61A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AE43BEC0-4BB7-42E1-B2B7-60A36092C61A}.Release|Any CPU.Build.0 = Release|Any CPU
{A9103B98-D888-4260-8A05-FA36F640698A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A9103B98-D888-4260-8A05-FA36F640698A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A9103B98-D888-4260-8A05-FA36F640698A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A9103B98-D888-4260-8A05-FA36F640698A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -802,18 +814,21 @@ Global
{E56BEA9A-B52A-4781-9FF4-217439923319} = {AF683E5C-421E-4DE0-ADD7-9841E5D12BFA}
{69C03400-12AC-4E4D-B970-6A880616BF68} = {580D1AE7-AA8F-4912-8B76-105594E00B3B}
{FAAC2E23-A460-40FE-9207-C10EEE5A6A07} = {580D1AE7-AA8F-4912-8B76-105594E00B3B}
{87AE3308-8CCB-4383-8F51-C5061E348C36} = {AF683E5C-421E-4DE0-ADD7-9841E5D12BFA}
{920F6448-C2D0-4B01-AC25-16214C5A6006} = {580D1AE7-AA8F-4912-8B76-105594E00B3B}
{9D08CED8-02CC-4566-A3B7-3434D205F0A2} = {AF683E5C-421E-4DE0-ADD7-9841E5D12BFA}
{68E743E6-5D4B-4CD4-941A-07285032451F} = {AF683E5C-421E-4DE0-ADD7-9841E5D12BFA}
{9D36039F-D0A1-462F-85B4-81763C6B02CB} = {AF683E5C-421E-4DE0-ADD7-9841E5D12BFA}
{03C5A84A-982B-4F38-AC73-AB832C645C4A} = {AF683E5C-421E-4DE0-ADD7-9841E5D12BFA}
{0A3C9AFD-F6E6-4A5D-83FB-93BF66732696} = {AF683E5C-421E-4DE0-ADD7-9841E5D12BFA}
{08A18C0B-8985-49EE-AC80-EFEEDF18BCC5} = {580D1AE7-AA8F-4912-8B76-105594E00B3B}
{AE43BEC0-4BB7-42E1-B2B7-60A36092C61A} = {580D1AE7-AA8F-4912-8B76-105594E00B3B}
{A9103B98-D888-4260-8A05-FA36F640698A} = {580D1AE7-AA8F-4912-8B76-105594E00B3B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FB8F26CE-4DE6-433F-B32A-79183020BBD6}
EndGlobalSection
GlobalSection(SharedMSBuildProjectFiles) = preSolution
src\Compatibility\Microsoft.DotNet.Compatibility.Shared\Microsoft.DotNet.Compatibility.Shared.projitems*{68e743e6-5d4b-4cd4-941a-07285032451f}*SharedItemsImports = 13
src\Compatibility\Microsoft.DotNet.Compatibility.Shared\Microsoft.DotNet.Compatibility.Shared.projitems*{87ae3308-8ccb-4383-8f51-c5061e348c36}*SharedItemsImports = 5
src\Compatibility\Microsoft.DotNet.Compatibility.Shared\Microsoft.DotNet.Compatibility.Shared.projitems*{9d08ced8-02cc-4566-a3b7-3434d205f0a2}*SharedItemsImports = 5
src\Compatibility\Microsoft.DotNet.ApiCompat.Shared\Microsoft.DotNet.ApiCompat.Shared.projitems*{03c5a84a-982b-4f38-ac73-ab832c645c4a}*SharedItemsImports = 5
src\Compatibility\Microsoft.DotNet.ApiCompat.Shared\Microsoft.DotNet.ApiCompat.Shared.projitems*{0a3c9afd-f6e6-4a5d-83fb-93bf66732696}*SharedItemsImports = 5
src\Compatibility\Microsoft.DotNet.ApiCompat.Shared\Microsoft.DotNet.ApiCompat.Shared.projitems*{9d36039f-d0a1-462f-85b4-81763c6b02cb}*SharedItemsImports = 13
src\Compatibility\Microsoft.DotNet.ApiCompat.Shared\Microsoft.DotNet.ApiCompat.Shared.projitems*{a9103b98-d888-4260-8a05-fa36f640698a}*SharedItemsImports = 5
EndGlobalSection
EndGlobal
3 changes: 2 additions & 1 deletion source-build.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
"src\\Cli\\Microsoft.DotNet.Configurer\\Microsoft.DotNet.Configurer.csproj",
"src\\Cli\\Microsoft.DotNet.InternalAbstractions\\Microsoft.DotNet.InternalAbstractions.csproj",
"src\\Cli\\dotnet\\dotnet.csproj",
"src\\Compatibility\\Microsoft.DotNet.ApiCompat.Shared\\Microsoft.DotNet.ApiCompat.Shared.shproj",
"src\\Compatibility\\Microsoft.DotNet.ApiCompat.Task\\Microsoft.DotNet.ApiCompat.Task.csproj",
"src\\Compatibility\\Microsoft.DotNet.ApiCompatibility\\Microsoft.DotNet.ApiCompatibility.csproj",
"src\\Compatibility\\Microsoft.DotNet.Compatibility\\Microsoft.DotNet.Compatibility.csproj",
"src\\Compatibility\\Microsoft.DotNet.PackageValidation\\Microsoft.DotNet.PackageValidation.csproj",
"src\\Layout\\redist\\redist.csproj",
"src\\Layout\\tool_fsharp\\tool_fsc.csproj",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="$(MSBuildProjectDirectory)\..\..\..\..\src\Compatibility\Microsoft.DotNet.Compatibility\Microsoft.DotNet.Compatibility.csproj" />
<ProjectReference Include="$(MSBuildProjectDirectory)\..\..\..\..\src\Compatibility\Microsoft.DotNet.ApiCompat.Task\Microsoft.DotNet.ApiCompat.Task.csproj" />
<PackageReference Include="NuGet.Frameworks" Version="6.0.0-preview.1.66" />
<PackageReference Include="NuGet.Packaging" Version="6.0.0-preview.1.66" />
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.1" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.0.0-1.21277.15" />
</ItemGroup>

<Import Project="$(MSBuildProjectDirectory)\..\..\..\..\src\Tasks\Microsoft.NET.Build.Tasks\targets\Microsoft.NET.Compatibility.targets" />
<Import Project="$(MSBuildProjectDirectory)\..\..\..\..\src\Tasks\Microsoft.NET.Build.Tasks\targets\Microsoft.NET.ApiCompat.targets" />

<PropertyGroup>
<DotNetCompatibilityAssembly Condition="'$(MSBuildRuntimeType)' != 'Core'">$(MSBuildThisFileDirectory)\bin\$(Configuration)\netstandard2.0\Microsoft.DotNet.Compatibility.dll</DotNetCompatibilityAssembly>
<DotNetCompatibilityAssembly Condition="'$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)\bin\$(Configuration)\net6.0\Microsoft.DotNet.Compatibility.dll</DotNetCompatibilityAssembly>
<DotNetPackageValidationTaskAssembly Condition="'$(MSBuildRuntimeType)' != 'Core'">$(MSBuildThisFileDirectory)\bin\$(Configuration)\net472\Microsoft.DotNet.ApiCompat.Task.dll</DotNetPackageValidationTaskAssembly>
<DotNetPackageValidationTaskAssembly Condition="'$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)\bin\$(Configuration)\net6.0\Microsoft.DotNet.ApiCompat.Task.dll</DotNetPackageValidationTaskAssembly>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,19 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="CreateWorkItemPerAssemblyAssembliesNotEqual" xml:space="preserve">
<value>When enqueuing work items per assembly, the number of passed in left and right assemblies must be equal.</value>
</data>
<data name="InvalidRexegStringTransformationPattern" xml:space="preserve">
<value>Invalid transformation pattern provided: '{0} - {1}'.</value>
</data>
<data name="SuppressionsFileNotSpecified" xml:space="preserve">
<value>A file path must be passed in to successfully generate a compatibility suppression file.</value>
</data>
<data name="UpdateSdkVersion" xml:space="preserve">
<value> The minimum version required of Roslyn is '{1}' and you are using '{0}' version of the Roslyn. You can update the sdk to get the latest version.</value>
<value>The minimum version required of Roslyn is '{1}' and you are using '{0}' version of the Roslyn. You can update the sdk to get the latest version.</value>
</data>
<data name="WroteSuppressions" xml:space="preserve">
<value>Successfully wrote compatibility suppressions to '{0}'.</value>
</data>
</root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects Condition="'$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' &lt; '16.0'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<SharedGUID>9d36039f-d0a1-462f-85b4-81763c6b02cb</SharedGUID>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<Import_RootNamespace>Microsoft.DotNet.ApiCompat</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)SuppressionFileHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ValidatePackage.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ValidateAssemblies.cs" />
<Compile Include="$(MSBuildThisFileDirectory)RegexStringTransformer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)RoslynResolver.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)CommonResources.resx" GenerateSource="true" SubType="Designer" Generator="MSBuild:_GenerateResxSource" ClassName="Microsoft.DotNet.ApiCompat.CommonResources" ManifestResourceName="Microsoft.DotNet.ApiCompat.CommonResources" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<ProjectGuid>68e743e6-5d4b-4cd4-941a-07285032451f</ProjectGuid>
<ProjectGuid>9d36039f-d0a1-462f-85b4-81763c6b02cb</ProjectGuid>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="Microsoft.DotNet.Compatibility.Shared.projitems" Label="Shared" />
<Import Project="Microsoft.DotNet.ApiCompat.Shared.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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.

using System;
using System.Text.RegularExpressions;

namespace Microsoft.DotNet.ApiCompat
{
/// <summary>
/// A regex string transformer that transforms an input string via a set of regex patterns and replacement strings.
/// </summary>
internal class RegexStringTransformer
{
private readonly (Regex Regex, string ReplacementString)[] _patterns;
// Define a timeout for regex matches to guard against malicious user inputs.
private static readonly TimeSpan s_regexTimeout = TimeSpan.FromSeconds(2);

/// <summary>
/// Initializes the regex string transformer with a given capture group and replacement patterns.
/// </summary>
/// <param name="captureGroupPattern">The capture group pattern to retrieve data that should be embedded into the replacement string.</param>
/// <param name="replacementString">The replacement string that contains the capture group markers (i.e. $1).</param>

public RegexStringTransformer(string captureGroupPattern, string replacementString)
: this(new (string, string)[] { (captureGroupPattern, replacementString) })
{
}

/// <summary>
/// Initializes the regex string transformer with the given capture group and replacement patterns.
/// </summary>
public RegexStringTransformer((string CaptureGroupPattern, string ReplacementString)[] rawPatterns)
{
_patterns = new (Regex Regex, string ReplacementString)[rawPatterns.Length];
for (int i = 0; i < rawPatterns.Length; i++)
{
_patterns[i] = (new Regex(rawPatterns[i].CaptureGroupPattern, RegexOptions.Compiled, s_regexTimeout), rawPatterns[i].ReplacementString);
}
}

/// <summary>
/// Transforms the input string via a regex pattern to a replacement string.
/// </summary>
/// <param name="input">The input string to transform.</param>
/// <returns>Returns the transformed input string. If the matches weren't successful, returns the untouched input.</returns>
public string Transform(string input)
{
string current = input;
foreach ((Regex regex, string replacementString) in _patterns)
{
current = regex.Replace(current, replacementString);
}

return current;
}
}
}
Loading