From 202c1edb60ff56688fbd6a214ab7e3c26d3ef519 Mon Sep 17 00:00:00 2001 From: Mateo Torres Ruiz Date: Fri, 8 Jan 2021 14:29:08 -0800 Subject: [PATCH 1/2] Remove single-file analyzer --- .../Core/AnalyzerReleases.Unshipped.md | 8 +- .../MicrosoftNetCoreAnalyzersResources.resx | 9 - .../AvoidAssemblyLocationInSingleFile.cs | 161 ----------------- .../MicrosoftNetCoreAnalyzersResources.cs.xlf | 15 -- .../MicrosoftNetCoreAnalyzersResources.de.xlf | 15 -- .../MicrosoftNetCoreAnalyzersResources.es.xlf | 15 -- .../MicrosoftNetCoreAnalyzersResources.fr.xlf | 15 -- .../MicrosoftNetCoreAnalyzersResources.it.xlf | 15 -- .../MicrosoftNetCoreAnalyzersResources.ja.xlf | 15 -- .../MicrosoftNetCoreAnalyzersResources.ko.xlf | 15 -- .../MicrosoftNetCoreAnalyzersResources.pl.xlf | 15 -- ...crosoftNetCoreAnalyzersResources.pt-BR.xlf | 15 -- .../MicrosoftNetCoreAnalyzersResources.ru.xlf | 15 -- .../MicrosoftNetCoreAnalyzersResources.tr.xlf | 15 -- ...osoftNetCoreAnalyzersResources.zh-Hans.xlf | 15 -- ...osoftNetCoreAnalyzersResources.zh-Hant.xlf | 15 -- .../Microsoft.CodeAnalysis.NetAnalyzers.md | 24 --- .../Microsoft.CodeAnalysis.NetAnalyzers.sarif | 40 ----- .../AvoidAssemblyLocationInSingleFileTests.cs | 167 ------------------ src/Utilities/Compiler/DiagnosticCategory.cs | 1 - .../DiagnosticCategoryAndIdRanges.txt | 6 +- .../Options/MSBuildPropertyOptionNames.cs | 2 - 22 files changed, 8 insertions(+), 605 deletions(-) delete mode 100644 src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Publish/AvoidAssemblyLocationInSingleFile.cs delete mode 100644 src/NetAnalyzers/UnitTests/Microsoft.NetCore.Analyzers/Publish/AvoidAssemblyLocationInSingleFileTests.cs diff --git a/src/NetAnalyzers/Core/AnalyzerReleases.Unshipped.md b/src/NetAnalyzers/Core/AnalyzerReleases.Unshipped.md index 0058139817..5f3c6ac8fb 100644 --- a/src/NetAnalyzers/Core/AnalyzerReleases.Unshipped.md +++ b/src/NetAnalyzers/Core/AnalyzerReleases.Unshipped.md @@ -1 +1,7 @@ -; Please do not edit this file manually, it should only be updated through code fix application. \ No newline at end of file +; Please do not edit this file manually, it should only be updated through code fix application. + +### Removed Rules +Rule ID | Category | Severity | Notes +--------|----------|----------|------- +IL3000 | Public | Warning | Moved analyzer to mono/linker +IL3001 | Public | Warning | Moved analyzer to mono/linker \ No newline at end of file diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/MicrosoftNetCoreAnalyzersResources.resx b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/MicrosoftNetCoreAnalyzersResources.resx index e240378b84..0b8e62a9ba 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/MicrosoftNetCoreAnalyzersResources.resx +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/MicrosoftNetCoreAnalyzersResources.resx @@ -1463,15 +1463,6 @@ Avoid 'StringBuilder' parameters for P/Invokes - - Avoid using accessing Assembly file path when publishing as a single-file - - - '{0}' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'. - - - '{0}' will throw for assemblies embedded in a single-file app - This call site is reachable on: {2}. '{0}' is only supported on: {1}. This call site is reachable on: 'windows' all versions.'SupportedOnWindowsUnsupportedFromWindows2004()' is only supported on: 'windows' 10.0.2004 and before diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Publish/AvoidAssemblyLocationInSingleFile.cs b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Publish/AvoidAssemblyLocationInSingleFile.cs deleted file mode 100644 index 505f561c5c..0000000000 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Publish/AvoidAssemblyLocationInSingleFile.cs +++ /dev/null @@ -1,161 +0,0 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using Analyzer.Utilities; -using Analyzer.Utilities.Extensions; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Diagnostics; -using Microsoft.CodeAnalysis.Operations; - -namespace Microsoft.NetCore.Analyzers.Publish -{ - /// - /// IL3000, IL3001: Do not use Assembly file path in single-file publish - /// - [DiagnosticAnalyzer(LanguageNames.CSharp, LanguageNames.VisualBasic)] - public sealed class AvoidAssemblyLocationInSingleFile : DiagnosticAnalyzer - { - public const string IL3000 = nameof(IL3000); - public const string IL3001 = nameof(IL3001); - - internal static DiagnosticDescriptor LocationRule = DiagnosticDescriptorHelper.Create( - IL3000, - new LocalizableResourceString(nameof(MicrosoftNetCoreAnalyzersResources.AvoidAssemblyLocationInSingleFileTitle), - MicrosoftNetCoreAnalyzersResources.ResourceManager, typeof(MicrosoftNetCoreAnalyzersResources)), - new LocalizableResourceString(nameof(MicrosoftNetCoreAnalyzersResources.AvoidAssemblyLocationInSingleFileMessage), - MicrosoftNetCoreAnalyzersResources.ResourceManager, typeof(MicrosoftNetCoreAnalyzersResources)), - DiagnosticCategory.Publish, - RuleLevel.BuildWarning, - description: null, - isPortedFxCopRule: false, - isDataflowRule: false); - - internal static DiagnosticDescriptor GetFilesRule = DiagnosticDescriptorHelper.Create( - IL3001, - new LocalizableResourceString(nameof(MicrosoftNetCoreAnalyzersResources.AvoidAssemblyLocationInSingleFileTitle), - MicrosoftNetCoreAnalyzersResources.ResourceManager, typeof(MicrosoftNetCoreAnalyzersResources)), - new LocalizableResourceString(nameof(MicrosoftNetCoreAnalyzersResources.AvoidAssemblyGetFilesInSingleFileMessage), - MicrosoftNetCoreAnalyzersResources.ResourceManager, typeof(MicrosoftNetCoreAnalyzersResources)), - DiagnosticCategory.Publish, - RuleLevel.BuildWarning, - description: null, - isPortedFxCopRule: false, - isDataflowRule: false); - - public override ImmutableArray SupportedDiagnostics => ImmutableArray.Create(LocationRule, GetFilesRule); - - public override void Initialize(AnalysisContext context) - { - context.EnableConcurrentExecution(); - context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.ReportDiagnostics); - - context.RegisterCompilationStartAction(context => - { - var compilation = context.Compilation; - var isSingleFilePublish = context.Options.GetMSBuildPropertyValue( - MSBuildPropertyOptionNames.PublishSingleFile, compilation, context.CancellationToken); - if (!string.Equals(isSingleFilePublish?.Trim(), "true", StringComparison.OrdinalIgnoreCase)) - { - return; - } - var includesAllContent = context.Options.GetMSBuildPropertyValue( - MSBuildPropertyOptionNames.IncludeAllContentForSelfExtract, compilation, context.CancellationToken); - if (string.Equals(includesAllContent?.Trim(), "true", StringComparison.OrdinalIgnoreCase)) - { - return; - } - - var propertiesBuilder = ImmutableArray.CreateBuilder(); - var methodsBuilder = ImmutableArray.CreateBuilder(); - - if (compilation.TryGetOrCreateTypeByMetadataName(WellKnownTypeNames.SystemReflectionAssembly, out var assemblyType)) - { - // properties - AddIfNotNull(propertiesBuilder, TryGetSingleSymbol(assemblyType.GetMembers("Location"))); - - // methods - methodsBuilder.AddRange(assemblyType.GetMembers("GetFile").OfType()); - methodsBuilder.AddRange(assemblyType.GetMembers("GetFiles").OfType()); - } - - if (compilation.TryGetOrCreateTypeByMetadataName(WellKnownTypeNames.SystemReflectionAssemblyName, out var assemblyNameType)) - { - AddIfNotNull(propertiesBuilder, TryGetSingleSymbol(assemblyNameType.GetMembers("CodeBase"))); - AddIfNotNull(propertiesBuilder, TryGetSingleSymbol(assemblyNameType.GetMembers("EscapedCodeBase"))); - } - - var properties = propertiesBuilder.ToImmutable(); - var methods = methodsBuilder.ToImmutable(); - - context.RegisterOperationAction(operationContext => - { - var access = (IPropertyReferenceOperation)operationContext.Operation; - var property = access.Property; - if (!Contains(properties, property, SymbolEqualityComparer.Default)) - { - return; - } - - operationContext.ReportDiagnostic(access.CreateDiagnostic(LocationRule, property)); - }, OperationKind.PropertyReference); - - context.RegisterOperationAction(operationContext => - { - var invocation = (IInvocationOperation)operationContext.Operation; - var targetMethod = invocation.TargetMethod; - if (!Contains(methods, targetMethod, SymbolEqualityComparer.Default)) - { - return; - } - - operationContext.ReportDiagnostic(invocation.CreateDiagnostic(GetFilesRule, targetMethod)); - }, OperationKind.Invocation); - - return; - - static bool Contains(ImmutableArray list, T elem, TComp comparer) - where TComp : IEqualityComparer - { - foreach (var e in list) - { - if (comparer.Equals(e, elem)) - { - return true; - } - } - return false; - } - - static TSymbol? TryGetSingleSymbol(ImmutableArray members) where TSymbol : class, ISymbol - { - TSymbol? candidate = null; - foreach (var m in members) - { - if (m is TSymbol tsym) - { - if (candidate is null) - { - candidate = tsym; - } - else - { - return null; - } - } - } - return candidate; - } - - static void AddIfNotNull(ImmutableArray.Builder properties, TSymbol? p) where TSymbol : class, ISymbol - { - if (p is not null) - { - properties.Add(p); - } - } - }); - } - } -} diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.cs.xlf b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.cs.xlf index be063a9c1a..714e9e49b4 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.cs.xlf +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.cs.xlf @@ -47,21 +47,6 @@ Literály řetězců atributů by se měly správně parsovat - - '{0}' will throw for assemblies embedded in a single-file app - Pro sestavení vložená do aplikace s jedním souborem {0} vyvolá výjimku. - - - - '{0}' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'. - Pro sestavení vložená do aplikace s jedním souborem {0} vždy vrátí prázdný řetězec. Pokud se cesta k adresáři aplikace vyžaduje, zvažte možnost zavolat System.AppContext.BaseDirectory. - - - - Avoid using accessing Assembly file path when publishing as a single-file - Při publikování jednoho souboru nepoužívat přístup k cestě souboru sestavení - - Marshalling of 'StringBuilder' always creates a native buffer copy, resulting in multiple allocations for one marshalling operation. Zařazením parametru StringBuilder se vždy vytvoří kopie nativní vyrovnávací paměti, která bude mít za následek vícenásobné přidělení pro jednu operaci zařazování. diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.de.xlf b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.de.xlf index 52ca3a058f..6e0f153a85 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.de.xlf +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.de.xlf @@ -47,21 +47,6 @@ Attributzeichenfolgenliterale müssen richtig analysiert werden - - '{0}' will throw for assemblies embedded in a single-file app - "{0}" wird für Assemblys ausgelöst, die in einer Einzeldatei-App eingebettet sind. - - - - '{0}' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'. - "{0}" gibt immer eine leere Zeichenfolge für Assemblys zurück, die in einer Einzeldatei-App eingebettet sind. Wenn der Pfad zum App-Verzeichnis erforderlich ist, sollten Sie "System.AppContext.BaseDirectory" aufrufen. - - - - Avoid using accessing Assembly file path when publishing as a single-file - Zugriff auf den Assemblydateipfad beim Veröffentlichen als Einzeldatei vermeiden - - Marshalling of 'StringBuilder' always creates a native buffer copy, resulting in multiple allocations for one marshalling operation. Beim Marshalling von "StringBuilder" wird immer eine native Pufferkopie erstellt, sodass mehrere Zuordnungen für einen Marshallingvorgang vorhanden sind. diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.es.xlf b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.es.xlf index 18668ee783..8c66938819 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.es.xlf +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.es.xlf @@ -47,21 +47,6 @@ Los literales de cadena de atributo se deben analizar correctamente - - '{0}' will throw for assemblies embedded in a single-file app - Se iniciará "{0}" para los ensamblados insertados en una aplicación de un solo archivo. - - - - '{0}' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'. - "{0}" devuelve siempre una cadena vacía para los ensamblados insertados en una aplicación de un solo archivo. Si se necesita la ruta de acceso al directorio de la aplicación, considere la posibilidad de llamar a "System.AppContext.BaseDirectory". - - - - Avoid using accessing Assembly file path when publishing as a single-file - Evite usar la ruta de acceso al archivo de ensamblado al publicar como único archivo - - Marshalling of 'StringBuilder' always creates a native buffer copy, resulting in multiple allocations for one marshalling operation. Al serializar "StringBuilder" siempre se crea una copia del búfer nativo, lo que da lugar a varias asignaciones para una operación de serialización. diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.fr.xlf b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.fr.xlf index d90f9ec3af..71a0c15261 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.fr.xlf +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.fr.xlf @@ -47,21 +47,6 @@ Les littéraux de chaîne d'attribut doivent être analysés correctement - - '{0}' will throw for assemblies embedded in a single-file app - '{0}' lèvera une exception pour les assemblys incorporés dans une application monofichier - - - - '{0}' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'. - '{0}' retourne toujours une chaîne vide pour les assemblys incorporés dans une application monofichier. Si le chemin du répertoire d'application est nécessaire, appelez 'System.AppContext.BaseDirectory'. - - - - Avoid using accessing Assembly file path when publishing as a single-file - Évitez d'utiliser l'accès du chemin du fichier d'assembly lors de la publication en tant qu'application monofichier - - Marshalling of 'StringBuilder' always creates a native buffer copy, resulting in multiple allocations for one marshalling operation. Le marshaling de 'StringBuilder' crée toujours une copie de la mémoire tampon native, ce qui entraîne plusieurs allocations pour une seule opération de marshaling. diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.it.xlf b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.it.xlf index 09c16a9f6e..61adbbacb6 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.it.xlf +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.it.xlf @@ -47,21 +47,6 @@ I valori letterali stringa dell'attributo devono essere analizzati correttamente - - '{0}' will throw for assemblies embedded in a single-file app - '{0}' verrà generato per gli assembly incorporati in un'app a file singolo - - - - '{0}' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'. - '{0}' restituisce sempre una stringa vuota per gli assembly incorporati in un'app a file singolo. Se il percorso della directory app è necessario, provare a chiamare 'System.AppContext.BaseDirectory'. - - - - Avoid using accessing Assembly file path when publishing as a single-file - Evitare l'accesso al percorso del file di assembly quando si esegue la pubblicazione come file singolo - - Marshalling of 'StringBuilder' always creates a native buffer copy, resulting in multiple allocations for one marshalling operation. Il marshalling di 'StringBuilder' crea sempre una copia del buffer nativo, di conseguenza vengono generate più allocazioni per una singola operazione di marshalling. diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.ja.xlf b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.ja.xlf index 6937c685a2..4faf2ebe51 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.ja.xlf +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.ja.xlf @@ -47,21 +47,6 @@ 属性文字列リテラルは、正しく解析する必要があります - - '{0}' will throw for assemblies embedded in a single-file app - '{0}' では、単一ファイル アプリに組み込まれているアセンブリのためにスローします - - - - '{0}' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'. - '{0}' は、単一ファイル アプリに埋め込まれているアセンブリに対して、常に空の文字列を返します。アプリ ディレクトリへのパスが必要な場合は、'System.AppContext.BaseDirectory' を呼び出すことを検討してください。 - - - - Avoid using accessing Assembly file path when publishing as a single-file - 単一ファイルとして発行するときにアセンブリ ファイル パスへのアクセスを使用しない - - Marshalling of 'StringBuilder' always creates a native buffer copy, resulting in multiple allocations for one marshalling operation. 'StringBuilder' をマーシャリングすると、ネイティブ バッファーのコピーが常に作成され、1 回のマーシャリング操作に対して複数の割り当てが発生します。 diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.ko.xlf b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.ko.xlf index d329428df3..42e160e005 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.ko.xlf +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.ko.xlf @@ -47,21 +47,6 @@ 특성 문자열 리터럴이 올바르게 구문 분석되어야 합니다. - - '{0}' will throw for assemblies embedded in a single-file app - '{0}'이(가) 단일 파일 앱에 포함된 어셈블리에 대해 throw합니다. - - - - '{0}' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'. - '{0}'은(는) 단일 파일 앱에 포함된 어셈블리에 대해 항상 빈 문자열을 반환합니다. 앱 디렉터리 경로가 필요한 경우 'System.AppContext.BaseDirectory'를 호출하는 것이 좋습니다. - - - - Avoid using accessing Assembly file path when publishing as a single-file - 단일 파일로 게시할 때 어셈블리 파일 경로 액세스를 사용하지 마세요. - - Marshalling of 'StringBuilder' always creates a native buffer copy, resulting in multiple allocations for one marshalling operation. 'StringBuilder'를 마샬링하는 경우 항상 네이티브 버퍼 복사본이 만들어지므로 하나의 마샬링 작업에 대해 할당이 여러 번 이루어집니다. diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.pl.xlf b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.pl.xlf index 0131fbd52a..dd9ad6db14 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.pl.xlf +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.pl.xlf @@ -47,21 +47,6 @@ Analiza literałów ciągu atrybutu powinna kończyć się powodzeniem - - '{0}' will throw for assemblies embedded in a single-file app - Element „{0}” będzie zgłaszać dla zestawów osadzonych w aplikacji jednoplikowej - - - - '{0}' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'. - Element „{0}” zawsze zwraca pusty ciąg dla zestawów osadzonych w aplikacji jednoplikowej. Jeśli potrzebna jest ścieżka do katalogu aplikacji, rozważ wywołanie elementu „System.AppContext.BaseDirectory”. - - - - Avoid using accessing Assembly file path when publishing as a single-file - Unikaj uzyskiwania dostępu do ścieżki pliku zestawu podczas publikowania w postaci jednoplikowej - - Marshalling of 'StringBuilder' always creates a native buffer copy, resulting in multiple allocations for one marshalling operation. Marshalling elementu „StringBuilder” zawsze tworzy natywną kopię buforu, co powoduje powstanie wielu alokacji dla jednej operacji marshallingu. diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.pt-BR.xlf b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.pt-BR.xlf index 9e63b6fc06..f73645c162 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.pt-BR.xlf +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.pt-BR.xlf @@ -47,21 +47,6 @@ Literais de cadeias de caracteres de atributos devem ser analisados corretamente - - '{0}' will throw for assemblies embedded in a single-file app - '{0}' será gerado para assemblies inseridos em um aplicativo de arquivo único - - - - '{0}' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'. - '{0}' sempre retorna uma cadeia de caracteres vazia para assemblies inseridos em um aplicativo de arquivo único. Se o caminho para o diretório do aplicativo for necessário, considere chamar 'System.AppContext.BaseDirectory'. - - - - Avoid using accessing Assembly file path when publishing as a single-file - Evite usar o acesso ao Caminho do arquivo do assembly na publicação como um arquivo único - - Marshalling of 'StringBuilder' always creates a native buffer copy, resulting in multiple allocations for one marshalling operation. O marshaling de 'StringBuilder' sempre cria uma cópia de buffer nativo, resultando em várias alocações para uma operação de marshalling. diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.ru.xlf b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.ru.xlf index 6dbafe9c23..3b853eaf7e 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.ru.xlf +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.ru.xlf @@ -47,21 +47,6 @@ Синтаксический анализ строковых литералов атрибута должен осуществляться правильно - - '{0}' will throw for assemblies embedded in a single-file app - Для сборок, внедренных в приложение с одним файлом, будет генерироваться "{0}". - - - - '{0}' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'. - "{0}" всегда возвращает пустую строку для сборок, внедренных в приложение с одним файлом. Если требуется путь к каталогу приложения, попробуйте вызвать "System.AppContext.BaseDirectory". - - - - Avoid using accessing Assembly file path when publishing as a single-file - Не используйте путь к файлу сборки при публикации в виде одного файла - - Marshalling of 'StringBuilder' always creates a native buffer copy, resulting in multiple allocations for one marshalling operation. При маршалировании "StringBuilder" всегда создается собственная копия буфера, что приводит к множественным выделениям для одной операции маршалирования. diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.tr.xlf b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.tr.xlf index c4dd09e3bd..e85849b540 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.tr.xlf +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.tr.xlf @@ -47,21 +47,6 @@ Öznitelik dizesinin sabit değerleri doğru ayrıştırılmalıdır - - '{0}' will throw for assemblies embedded in a single-file app - '{0}', tek dosyalı bir uygulamaya eklenen bütünleştirilmiş kodlar için özel durum oluşturur - - - - '{0}' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'. - '{0}', tek dosyalı bir uygulamaya eklenen bütünleştirilmiş kodlar için her zaman boş bir dize döndürür. Uygulama dizininin yolu gerekiyorsa 'System.AppContext.BaseDirectory' özelliğini çağırmayı düşünün. - - - - Avoid using accessing Assembly file path when publishing as a single-file - Tek dosyalı olarak yayımlarken bütünleştirilmiş kod dosyası yoluna erişimi kullanmaktan kaçının - - Marshalling of 'StringBuilder' always creates a native buffer copy, resulting in multiple allocations for one marshalling operation. 'StringBuilder' öğesinin hazırlanması her zaman, bir hazırlama işlemi için birden çok ayırmaya neden olan yerel arabellek kopyası oluşturur. diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.zh-Hans.xlf b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.zh-Hans.xlf index 1a161cab86..2548f9f6f3 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.zh-Hans.xlf +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.zh-Hans.xlf @@ -47,21 +47,6 @@ 特性字符串文本应正确分析 - - '{0}' will throw for assemblies embedded in a single-file app - 对于嵌入在单文件应用中的程序集,将引发“{0}” - - - - '{0}' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'. - 对于嵌入在单文件应用中的程序集,“{0}”始终返回空字符串。如果需要应用目录的路径,请考虑调用 "System.AppContext.BaseDirectory"。 - - - - Avoid using accessing Assembly file path when publishing as a single-file - 在以单文件形式发布时,避免使用访问程序集文件路径 - - Marshalling of 'StringBuilder' always creates a native buffer copy, resulting in multiple allocations for one marshalling operation. "StringBuilder" 的封送处理总是会创建一个本机缓冲区副本,这导致一个封送处理操作出现多次分配。 diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.zh-Hant.xlf b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.zh-Hant.xlf index 7bd5957db2..1aebe6df07 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.zh-Hant.xlf +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.zh-Hant.xlf @@ -47,21 +47,6 @@ 屬性字串常值應正確剖析 - - '{0}' will throw for assemblies embedded in a single-file app - '{0}' 將會為內嵌在單一檔案應用程式中的組件進行擲回 - - - - '{0}' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'. - '{0}' 一律會為內嵌在單一檔案應用程式中的組件傳回空字串。若需要應用程式目錄的路徑,請考慮呼叫 'System.AppContext.BaseDirectory'。 - - - - Avoid using accessing Assembly file path when publishing as a single-file - 以單一檔案形式發佈時,避免使用正在存取的組件檔案路徑 - - Marshalling of 'StringBuilder' always creates a native buffer copy, resulting in multiple allocations for one marshalling operation. 封送處理 'StringBuilder' 一律都會建立原生緩衝區複本,因而導致單一封送處理作業出現多重配置。 diff --git a/src/NetAnalyzers/Microsoft.CodeAnalysis.NetAnalyzers.md b/src/NetAnalyzers/Microsoft.CodeAnalysis.NetAnalyzers.md index 1dff4237dc..7fe18e9c6a 100644 --- a/src/NetAnalyzers/Microsoft.CodeAnalysis.NetAnalyzers.md +++ b/src/NetAnalyzers/Microsoft.CodeAnalysis.NetAnalyzers.md @@ -2927,27 +2927,3 @@ Hard-coded certificates in source code are vulnerable to being exploited. |Severity|Warning| |CodeFix|False| --- - -## [IL3000](https://docs.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/il3000): Avoid using accessing Assembly file path when publishing as a single-file - -'{0}' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'. - -|Item|Value| -|-|-| -|Category|Publish| -|Enabled|True| -|Severity|Warning| -|CodeFix|False| ---- - -## [IL3001](https://docs.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/il3001): Avoid using accessing Assembly file path when publishing as a single-file - -'{0}' will throw for assemblies embedded in a single-file app - -|Item|Value| -|-|-| -|Category|Publish| -|Enabled|True| -|Severity|Warning| -|CodeFix|False| ---- diff --git a/src/NetAnalyzers/Microsoft.CodeAnalysis.NetAnalyzers.sarif b/src/NetAnalyzers/Microsoft.CodeAnalysis.NetAnalyzers.sarif index 3f418be3a1..9646ae0112 100644 --- a/src/NetAnalyzers/Microsoft.CodeAnalysis.NetAnalyzers.sarif +++ b/src/NetAnalyzers/Microsoft.CodeAnalysis.NetAnalyzers.sarif @@ -5014,46 +5014,6 @@ "EnabledRuleInAggressiveMode" ] } - }, - "IL3000": { - "id": "IL3000", - "shortDescription": "Avoid using accessing Assembly file path when publishing as a single-file", - "fullDescription": "'{0}' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'.", - "defaultLevel": "warning", - "helpUri": "https://docs.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/il3000", - "properties": { - "category": "Publish", - "isEnabledByDefault": true, - "typeName": "AvoidAssemblyLocationInSingleFile", - "languages": [ - "C#", - "Visual Basic" - ], - "tags": [ - "Telemetry", - "EnabledRuleInAggressiveMode" - ] - } - }, - "IL3001": { - "id": "IL3001", - "shortDescription": "Avoid using accessing Assembly file path when publishing as a single-file", - "fullDescription": "'{0}' will throw for assemblies embedded in a single-file app", - "defaultLevel": "warning", - "helpUri": "https://docs.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/il3001", - "properties": { - "category": "Publish", - "isEnabledByDefault": true, - "typeName": "AvoidAssemblyLocationInSingleFile", - "languages": [ - "C#", - "Visual Basic" - ], - "tags": [ - "Telemetry", - "EnabledRuleInAggressiveMode" - ] - } } } }, diff --git a/src/NetAnalyzers/UnitTests/Microsoft.NetCore.Analyzers/Publish/AvoidAssemblyLocationInSingleFileTests.cs b/src/NetAnalyzers/UnitTests/Microsoft.NetCore.Analyzers/Publish/AvoidAssemblyLocationInSingleFileTests.cs deleted file mode 100644 index 780cb653cc..0000000000 --- a/src/NetAnalyzers/UnitTests/Microsoft.NetCore.Analyzers/Publish/AvoidAssemblyLocationInSingleFileTests.cs +++ /dev/null @@ -1,167 +0,0 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Threading.Tasks; -using Microsoft.CodeAnalysis.Testing; -using Xunit; -using VerifyCS = Test.Utilities.CSharpCodeFixVerifier< - Microsoft.NetCore.Analyzers.Publish.AvoidAssemblyLocationInSingleFile, - Microsoft.CodeAnalysis.Testing.EmptyCodeFixProvider>; -using static Analyzer.Utilities.MSBuildPropertyOptionNames; -using static Microsoft.NetCore.Analyzers.Publish.AvoidAssemblyLocationInSingleFile; - -namespace Microsoft.NetCore.Analyzers.Publish.UnitTests -{ - public class AvoidAssemblyLocationInSingleFileTests - { - [Theory] - [CombinatorialData] - public Task GetExecutingAssemblyLocation( - [CombinatorialValues(true, false, null)] bool? publish, - [CombinatorialValues(true, false, null)] bool? includeContent) - { - const string source = @" -using System.Reflection; -class C -{ - public string M() => Assembly.GetExecutingAssembly().Location; -}"; - string analyzerConfig = ""; - if (publish is not null) - { - analyzerConfig += $"build_property.{PublishSingleFile} = {publish}" + Environment.NewLine; - } - if (includeContent is not null) - { - analyzerConfig += $"build_property.{IncludeAllContentForSelfExtract} = {includeContent}"; - } - - var test = new VerifyCS.Test - { - TestCode = source, - AnalyzerConfigDocument = analyzerConfig - }; - - DiagnosticResult[] diagnostics; - if (publish is true && includeContent is not true) - { - diagnostics = new DiagnosticResult[] { - // /0/Test0.cs(5,26): warning IL3000: 'System.Reflection.Assembly.Location' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'. - VerifyCS.Diagnostic(AvoidAssemblyLocationInSingleFile.IL3000).WithSpan(5, 26, 5, 66).WithArguments("System.Reflection.Assembly.Location"), - }; - } - else - { - diagnostics = Array.Empty(); - } - - test.ExpectedDiagnostics.AddRange(diagnostics); - return test.RunAsync(); - } - - [Fact] - public Task AssemblyProperties() - { - var src = @" -using System.Reflection; -class C -{ - public void M() - { - var a = Assembly.GetExecutingAssembly(); - _ = a.Location; - // below will be obsolete in 5.0 - _ = a.CodeBase; - _ = a.EscapedCodeBase; - } -}"; - return VerifyDiagnosticsAsync(src, - // /0/Test0.cs(8,13): warning IL3000: 'System.Reflection.Assembly.Location' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'. - VerifyCS.Diagnostic(AvoidAssemblyLocationInSingleFile.IL3000).WithSpan(8, 13, 8, 23).WithArguments("System.Reflection.Assembly.Location") - ); - } - - [Fact] - public Task AssemblyMethods() - { - var src = @" -using System.Reflection; -class C -{ - public void M() - { - var a = Assembly.GetExecutingAssembly(); - _ = a.GetFile(""/some/file/path""); - _ = a.GetFiles(); - } -}"; - return VerifyDiagnosticsAsync(src, - // /0/Test0.cs(8,13): warning IL3001: Assemblies embedded in a single-file app cannot have additional files in the manifest. - VerifyCS.Diagnostic(AvoidAssemblyLocationInSingleFile.IL3001).WithSpan(8, 13, 8, 41).WithArguments("System.Reflection.Assembly.GetFile(string)"), - // /0/Test0.cs(9,13): warning IL3001: Assemblies embedded in a single-file app cannot have additional files in the manifest. - VerifyCS.Diagnostic(AvoidAssemblyLocationInSingleFile.IL3001).WithSpan(9, 13, 9, 25).WithArguments("System.Reflection.Assembly.GetFiles()") - ); - } - - [Fact] - public Task AssemblyNameAttributes() - { - var src = @" -using System.Reflection; -class C -{ - public void M() - { - var a = Assembly.GetExecutingAssembly().GetName(); - _ = a.CodeBase; - _ = a.EscapedCodeBase; - } -}"; - return VerifyDiagnosticsAsync(src, - // /0/Test0.cs(8,13): warning IL3000: 'System.Reflection.AssemblyName.CodeBase' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'. - VerifyCS.Diagnostic(AvoidAssemblyLocationInSingleFile.IL3000).WithSpan(8, 13, 8, 23).WithArguments("System.Reflection.AssemblyName.CodeBase"), - // /0/Test0.cs(9,13): warning IL3000: 'System.Reflection.AssemblyName.EscapedCodeBase' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'. - VerifyCS.Diagnostic(AvoidAssemblyLocationInSingleFile.IL3000).WithSpan(9, 13, 9, 30).WithArguments("System.Reflection.AssemblyName.EscapedCodeBase") - ); - } - - [Fact] - public Task FalsePositive() - { - // This is an OK use of Location and GetFile since these assemblies were loaded from - // a file, but the analyzer is conservative - var src = @" -using System.Reflection; -class C -{ - public void M() - { - var a = Assembly.LoadFrom(""/some/path/not/in/bundle""); - _ = a.Location; - _ = a.GetFiles(); - } -}"; - return VerifyDiagnosticsAsync(src, - // /0/Test0.cs(8,13): warning IL3000: 'System.Reflection.Assembly.Location' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'. - VerifyCS.Diagnostic(AvoidAssemblyLocationInSingleFile.IL3000).WithSpan(8, 13, 8, 23).WithArguments("System.Reflection.Assembly.Location"), - // /0/Test0.cs(9,13): warning IL3001: Assemblies embedded in a single-file app cannot have additional files in the manifest. - VerifyCS.Diagnostic(AvoidAssemblyLocationInSingleFile.IL3001).WithSpan(9, 13, 9, 25).WithArguments("System.Reflection.Assembly.GetFiles()") - ); - } - - private Task VerifyDiagnosticsAsync(string source, params DiagnosticResult[] expected) - { - const string singleFilePublishConfig = @" -build_property." + PublishSingleFile + " = true"; - - var test = new VerifyCS.Test - { - TestCode = source, - AnalyzerConfigDocument = singleFilePublishConfig - }; - - test.ExpectedDiagnostics.AddRange(expected); - return test.RunAsync(); - } - } -} \ No newline at end of file diff --git a/src/Utilities/Compiler/DiagnosticCategory.cs b/src/Utilities/Compiler/DiagnosticCategory.cs index 69def675b9..3b32ebccb3 100644 --- a/src/Utilities/Compiler/DiagnosticCategory.cs +++ b/src/Utilities/Compiler/DiagnosticCategory.cs @@ -16,7 +16,6 @@ internal static class DiagnosticCategory public const string Library = nameof(Library); public const string Documentation = nameof(Documentation); public const string Maintainability = nameof(Maintainability); - public const string Publish = nameof(Publish); public const string RoslynDiagnosticsDesign = nameof(RoslynDiagnosticsDesign); public const string RoslynDiagnosticsMaintainability = nameof(RoslynDiagnosticsMaintainability); diff --git a/src/Utilities/Compiler/DiagnosticCategoryAndIdRanges.txt b/src/Utilities/Compiler/DiagnosticCategoryAndIdRanges.txt index 793ed1c657..94d4940230 100644 --- a/src/Utilities/Compiler/DiagnosticCategoryAndIdRanges.txt +++ b/src/Utilities/Compiler/DiagnosticCategoryAndIdRanges.txt @@ -35,8 +35,4 @@ RoslynDiagnosticsDesign: RS0000-RS0999 RoslynDiagnosticsMaintainability: RS0000-RS0999 RoslynDiagnosticsPerformance: RS0000-RS0999 RoslynDiagnosticsReliability: RS0000-RS0999 -RoslynDiagnosticsUsage: RS0000-RS0999 - -# dotnet publish rules -# These are warnings for single-file publish or the IL trimmer -Publish: IL0000-IL9999 \ No newline at end of file +RoslynDiagnosticsUsage: RS0000-RS0999 \ No newline at end of file diff --git a/src/Utilities/Compiler/Options/MSBuildPropertyOptionNames.cs b/src/Utilities/Compiler/Options/MSBuildPropertyOptionNames.cs index 891cd4de94..5e4940793b 100644 --- a/src/Utilities/Compiler/Options/MSBuildPropertyOptionNames.cs +++ b/src/Utilities/Compiler/Options/MSBuildPropertyOptionNames.cs @@ -17,8 +17,6 @@ internal static class MSBuildPropertyOptionNames public const string TargetPlatformMinVersion = nameof(TargetPlatformMinVersion); public const string UsingMicrosoftNETSdkWeb = nameof(UsingMicrosoftNETSdkWeb); public const string ProjectTypeGuids = nameof(ProjectTypeGuids); - public const string PublishSingleFile = nameof(PublishSingleFile); - public const string IncludeAllContentForSelfExtract = nameof(IncludeAllContentForSelfExtract); } internal static class MSBuildPropertyOptionNamesHelpers From 89f58a2361a8252f93b2bbbbc8f0e033e311b136 Mon Sep 17 00:00:00 2001 From: Manish Vasani Date: Mon, 11 Jan 2021 09:46:14 -0800 Subject: [PATCH 2/2] Update src/NetAnalyzers/Core/AnalyzerReleases.Unshipped.md --- src/NetAnalyzers/Core/AnalyzerReleases.Unshipped.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/NetAnalyzers/Core/AnalyzerReleases.Unshipped.md b/src/NetAnalyzers/Core/AnalyzerReleases.Unshipped.md index 332cd78356..64372afc0b 100644 --- a/src/NetAnalyzers/Core/AnalyzerReleases.Unshipped.md +++ b/src/NetAnalyzers/Core/AnalyzerReleases.Unshipped.md @@ -1,6 +1,7 @@ ; Please do not edit this file manually, it should only be updated through code fix application. ### Removed Rules + Rule ID | Category | Severity | Notes --------|----------|----------|------- CA1801 | Usage | Disabled | ReviewUnusedParametersAnalyzer, [Documentation](https://docs.microsoft.com/visualstudio/code-quality/ca1801)