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

Enable single file analyzer in the runtime #50894

Merged
merged 32 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
937f893
Enable single file analyzer in the runtime
Apr 8, 2021
1b3dc8e
Merge branch 'main' into SingleFileAnalyzerOnRuntime
tlakollo Apr 8, 2021
f839417
Add IL3002 to CodeAnalysis.test.ruleset to avoid warning on tests
Apr 9, 2021
f92327e
Merge branch 'SingleFileAnalyzerOnRuntime' of https://github.com/tlak…
Apr 9, 2021
ae1bd07
Fix formating of CustomAttribute
Apr 9, 2021
23828b9
Fix introduced typo
Apr 9, 2021
9ec8520
Merge branch 'main' of https://github.com/dotnet/runtime into SingleF…
Apr 9, 2021
eba095e
Merge branch 'main' of https://github.com/dotnet/runtime into SingleF…
Apr 12, 2021
67dbd63
Merge branch 'main' of https://github.com/dotnet/runtime into SingleF…
Apr 14, 2021
63a395a
Fix some formatting/comments/extra pragma
Apr 14, 2021
91ecb47
Fix UnconditionalSuppressMessage when TFM != NetCoreAppCurrent
Apr 14, 2021
eb6d83a
Add more UnconditionalSuppressMessage support for TFM !=
Apr 14, 2021
4bfc9a8
Fix incompatibility in EventLog.csproj
Apr 14, 2021
6367cb9
Add System.Diagnostics.Tools if TFM is netcoreapp3.0 on
Apr 14, 2021
6bad341
Address some PR comments
Apr 16, 2021
0597dde
Merge branch 'main' of https://github.com/dotnet/runtime into SingleF…
Apr 26, 2021
4786f73
Change code in DependencyContext to not use Lazy
Apr 27, 2021
33f6916
PR feedback
Apr 28, 2021
b232294
Redo changes in MetadataLoadContext.csproj after checking out the main
Apr 28, 2021
2947adb
Merge branch 'main' of https://github.com/dotnet/runtime into SingleF…
Apr 28, 2021
f120ae9
Delete extra code
Apr 28, 2021
874f872
Disable SingleFileAnalyzer for Microsoft.XmlSerializer.Generator and
Apr 28, 2021
1debcce
Merge branch 'main' into SingleFileAnalyzerOnRuntime
tlakollo Apr 29, 2021
870dc92
Missing message change
Apr 29, 2021
670bdcb
Merge branch 'SingleFileAnalyzerOnRuntime' of https://github.com/tlak…
Apr 29, 2021
dbb0690
PR feedback
tlakollo Apr 29, 2021
0994fec
Merge branch 'main' of https://github.com/dotnet/runtime into SingleF…
tlakollo May 12, 2021
2d47bad
Merge branch 'main' of https://github.com/dotnet/runtime into SingleF…
tlakollo May 12, 2021
df3c4bd
Merge branch 'main' of https://github.com/dotnet/runtime into SingleF…
tlakollo May 14, 2021
c2dc595
Change UnconditionalSuppressMessage for SuppressMessage since SingleFile
tlakollo May 14, 2021
ff7f84f
Merge branch 'main' of https://github.com/dotnet/runtime into SingleF…
tlakollo May 17, 2021
305b675
Merge branch 'main' of https://github.com/dotnet/runtime into SingleF…
tlakollo May 19, 2021
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
2 changes: 2 additions & 0 deletions eng/Analyzers.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
<CodeAnalysisRuleset>$(MSBuildThisFileDirectory)CodeAnalysis.ruleset</CodeAnalysisRuleset>
<!-- Disable analyzers in sourcebuild -->
<RunAnalyzers Condition="'$(DotNetBuildFromSource)' == 'true'">false</RunAnalyzers>
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
</PropertyGroup>
<ItemGroup Condition="'$(RunAnalyzers)' != 'false'">
<PackageReference Include="Microsoft.DotNet.CodeAnalysis" Version="$(MicrosoftDotNetCodeAnalysisVersion)" PrivateAssets="all" IsImplicitlyDefined="true" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="$(MicrosoftCodeAnalysisNetAnalyzersVersion)" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="$(MicrosoftCodeAnalysisCSharpCodeStyleVersion)" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" Version="$(StyleCopAnalyzersVersion)" PrivateAssets="all" />
<PackageReference Include="Microsoft.NET.ILLink.Analyzers" Version="$(MicrosoftNETILLinkAnalyzerPackageVersion)" PrivateAssets="all" />
</ItemGroup>
</Project>
2 changes: 0 additions & 2 deletions eng/CodeAnalysis.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,6 @@
<Rule Id="CA5401" Action="None" /> <!-- Do not use CreateEncryptor with non-default IV -->
<Rule Id="CA5402" Action="None" /> <!-- Use CreateEncryptor with the default IV -->
<Rule Id="CA5403" Action="None" /> <!-- Do not hard-code certificate -->
<Rule Id="IL3000" Action="None" /> <!-- Avoid using accessing Assembly file path when publishing as a single-file -->
<Rule Id="IL3001" Action="None" /> <!-- Avoid using accessing Assembly file path when publishing as a single-file -->
</Rules>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="AD0001" Action="None" /> <!-- Analyzer threw an exception -->
Expand Down
1 change: 1 addition & 0 deletions eng/CodeAnalysis.test.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@
<Rule Id="CA5403" Action="None" /> <!-- Do not hard-code certificate -->
<Rule Id="IL3000" Action="None" /> <!-- Avoid using accessing Assembly file path when publishing as a single-file -->
<Rule Id="IL3001" Action="None" /> <!-- Avoid using accessing Assembly file path when publishing as a single-file -->
<Rule Id="IL3002" Action="None" /> <!-- Using member with RequiresAssemblyFilesAttribute can break functionality when embedded in a single-file app -->
</Rules>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="AD0001" Action="None" /> <!-- Analyzer threw an exception -->
Expand Down
1 change: 1 addition & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
<MicrosoftPrivateIntellisenseVersion>5.0.0-preview-20201009.2</MicrosoftPrivateIntellisenseVersion>
<!-- ILLink -->
<MicrosoftNETILLinkTasksVersion>6.0.100-preview.2.21226.1</MicrosoftNETILLinkTasksVersion>
<MicrosoftNETILLinkAnalyzerPackageVersion>$(MicrosoftNETILLinkTasksVersion)</MicrosoftNETILLinkAnalyzerPackageVersion>
<!-- ICU -->
<MicrosoftNETCoreRuntimeICUTransportVersion>6.0.0-preview.5.21219.2</MicrosoftNETCoreRuntimeICUTransportVersion>
<!-- Mono LLVM -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;

namespace Microsoft.Extensions.DependencyModel
{
public class DependencyContext
{
private static readonly Lazy<DependencyContext> _defaultContext = new Lazy<DependencyContext>(LoadDefault);
tlakollo marked this conversation as resolved.
Show resolved Hide resolved
private static bool _isDefaultContextInitialized;

private static DependencyContext _defaultContext;

public DependencyContext(TargetInfo target,
CompilationOptions compilationOptions,
Expand Down Expand Up @@ -46,7 +49,19 @@ public DependencyContext(TargetInfo target,
RuntimeGraph = runtimeGraph.ToArray();
}

public static DependencyContext Default => _defaultContext.Value;
[RequiresAssemblyFiles(Message = "DependencyContext for an assembly from a application published as single-file is not supported. The method will return null. Make sure the calling code can handle this case.")]
public static DependencyContext Default
{
get
{
if (_isDefaultContextInitialized == false) {
tlakollo marked this conversation as resolved.
Show resolved Hide resolved
_defaultContext = LoadDefault();
_isDefaultContextInitialized = true;
}
return _defaultContext;
}
}


public TargetInfo Target { get; }

Expand Down Expand Up @@ -74,6 +89,7 @@ public DependencyContext Merge(DependencyContext other)
);
}

[RequiresAssemblyFiles(Message = "DependencyContext for an assembly from a application published as single-file is not supported. The method will return null. Make sure the calling code can handle this case.")]
private static DependencyContext LoadDefault()
{
var entryAssembly = Assembly.GetEntryAssembly();
Expand All @@ -85,6 +101,7 @@ private static DependencyContext LoadDefault()
return Load(entryAssembly);
}

[RequiresAssemblyFiles(Message = "DependencyContext for an assembly from a application published as single-file is not supported. The method will return null. Make sure the calling code can handle this case.")]
public static DependencyContext Load(Assembly assembly)
{
return DependencyContextLoader.Default.Load(assembly);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Reflection;

Expand Down Expand Up @@ -50,6 +51,7 @@ private static Stream GetResourceStream(Assembly assembly, string name)
return assembly.GetManifestResourceStream(name);
}

[RequiresAssemblyFiles(Message = "DependencyContext for an assembly from a application published as single-file is not supported. The method will return null. Make sure the calling code can handle this case.")]
public DependencyContext Load(Assembly assembly)
{
if (assembly == null)
Expand Down Expand Up @@ -103,6 +105,7 @@ private DependencyContext LoadContext(IDependencyContextReader reader, string lo
return null;
}

[RequiresAssemblyFiles(Message = "DependencyContext for an assembly from a application published as single-file is not supported. The method will return null. Make sure the calling code can handle this case.")]
private DependencyContext LoadAssemblyContext(Assembly assembly, IDependencyContextReader reader)
{
using (Stream stream = GetResourceStream(assembly, assembly.GetName().Name + DepsJsonExtension))
Expand All @@ -125,6 +128,7 @@ private DependencyContext LoadAssemblyContext(Assembly assembly, IDependencyCont
return null;
}

[RequiresAssemblyFiles(Message = "The use of DependencyContextLoader is not supported when publishing as single-file")]
private string GetDepsJsonPath(Assembly assembly)
{
// Assemblies loaded in memory (e.g. single file) return empty string from Location.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@
<ProjectReference Include="$(LibrariesProjectRoot)System.Text.Encodings.Web\src\System.Text.Encodings.Web.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Text.Json\src\System.Text.Json.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\RequiresAssemblyFilesAttribute.cs" />
tlakollo marked this conversation as resolved.
Show resolved Hide resolved
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Reflection;

Expand All @@ -27,6 +28,8 @@ public static void Enable()
// has run.
}

[UnconditionalSuppressMessage("Single file", "IL3000:Avoid accessing Assembly file path when publishing as a single file",
Justification = "The code has a fallback to use AppDomain.CurrentDomain.BaseDirectory so it will work correctly in single-file")]
private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
// apply any existing policy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<ItemGroup Condition="'$(TargetFramework)' == 'net472'">
<Compile Include="BuildTask.Desktop.cs" />
<Compile Include="AssemblyResolver.cs" />
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\UnconditionalSuppressMessageAttribute.cs" />
</ItemGroup>

<ItemGroup>
Expand All @@ -37,7 +38,7 @@
<Content Condition="'$(AdditionalRuntimeIdentifiers)' != ''" Include="$(IntermediateOutputPath)runtime.json" PackagePath="/" />
<Content Include="_._" PackagePath="lib/netstandard1.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Build" Version="$(RefOnlyMicrosoftBuildVersion)" />
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="$(RefOnlyMicrosoftBuildTasksCoreVersion)" />
Expand All @@ -54,4 +55,4 @@
</Target>

<Import Project="runtimeGroups.props" />
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@
<OutputType>Exe</OutputType>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
</PropertyGroup>

tlakollo marked this conversation as resolved.
Show resolved Hide resolved
<ItemGroup>
<Compile Include="Sgen.cs" />
</ItemGroup>

<ItemGroup>
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\UnconditionalSuppressMessageAttribute.cs" />
tlakollo marked this conversation as resolved.
Show resolved Hide resolved
</ItemGroup>

<Import Project=".\GenerateThisAssemblyCs.targets" />

</Project>
12 changes: 9 additions & 3 deletions src/libraries/Microsoft.XmlSerializer.Generator/src/Sgen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -206,6 +207,8 @@ private int Run(string[] args)
return 0;
}

[UnconditionalSuppressMessage("Single file", "IL3000: Avoid accessing Assembly file path when publishing as a single file",
Justification = "Code has a fallback and thus works in single-file")]
private void GenerateFile(List<string> typeNames, string assemblyName, bool proxyOnly, bool silent, bool warnings, bool force, string outputDirectory, bool parsableerrors)
{
Assembly assembly = LoadAssembly(assemblyName, true);
Expand Down Expand Up @@ -293,6 +296,9 @@ private void GenerateFile(List<string> typeNames, string assemblyName, bool prox
ImportType(type, mappings, importedTypes, warnings, importer, parsableerrors);
}
}
string nameOrLocation = assembly.Location;
if (nameOrLocation == string.Empty)
tlakollo marked this conversation as resolved.
Show resolved Hide resolved
nameOrLocation = assembly.FullName;

if (importedTypes.Count > 0)
{
Expand Down Expand Up @@ -369,17 +375,17 @@ private void GenerateFile(List<string> typeNames, string assemblyName, bool prox
if (!silent)
{
Console.Out.WriteLine(SR.Format(SR.InfoFileName, codePath));
Console.Out.WriteLine(SR.Format(SR.InfoGeneratedFile, assembly.Location, codePath));
Console.Out.WriteLine(SR.Format(SR.InfoGeneratedFile, nameOrLocation, codePath));
}
}
else
{
Console.Out.WriteLine(FormatMessage(parsableerrors, false, SR.Format(SR.ErrGenerationFailed, assembly.Location)));
Console.Out.WriteLine(FormatMessage(parsableerrors, false, SR.Format(SR.ErrGenerationFailed, nameOrLocation)));
}
}
else
{
Console.Out.WriteLine(FormatMessage(parsableerrors, true, SR.Format(SR.InfoNoSerializableTypes, assembly.Location)));
Console.Out.WriteLine(FormatMessage(parsableerrors, true, SR.Format(SR.InfoNoSerializableTypes, nameOrLocation)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@
<Compile Include="$(CommonPath)System\Composition\Diagnostics\TraceWriter.cs"
Link="Common\System\Composition\Diagnostics\TraceWriter.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != '$(NetCoreAppCurrent)'">
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\UnconditionalSuppressMessageAttribute.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'netstandard2.0'">
<Reference Include="Microsoft.Win32.Primitives" />
<Reference Include="System.Collections" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,8 @@ private void ThrowIfDisposed()
private string GetDisplayName() =>
$"{GetType().Name} (Assembly=\"{Assembly.FullName}\")"; // NOLOC

[UnconditionalSuppressMessage("Single file", "IL3000: Avoid accessing Assembly file path when publishing as a single file",
Justification = "Setting a CodeBase is single file compatible")]
Copy link
Member

Choose a reason for hiding this comment

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

Did you look at only making the getter for CodeBase "unsafe" and leave the setter without an attribute?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the annotation is in the getter of codebase in the file src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyName.cs in this PR.
I didn't change the analyzer behavior for now since it will mean more work to special case the codebase getter in the analyzer. The plan is to annotate first, then get rid of the special casing in the analyzers for CodeBase/EscapedCodeBase since they are deprecated and provide a misleading warning, and once the analyzer doesn't check for those we can delete the UnconditionalSuppressMessage and tests in the linker. Also cannot remove it for now since the annotations are not in place and we wouldn't warn.

private static Assembly LoadAssembly(string codeBase)
{
Requires.NotNullOrEmpty(codeBase, nameof(codeBase));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Reflection;
using System.Collections;
Expand Down Expand Up @@ -57,6 +58,8 @@ private string GetLocalPath(string fileName)
return uri.LocalPath + uri.Fragment;
}

[UnconditionalSuppressMessage("Single file", "IL3000: Avoid accessing Assembly file path when publishing as a single file",
Justification = "Suppressing the warning until gets fixed, see https://github.com/dotnet/runtime/issues/50821")]
Copy link
Member

Choose a reason for hiding this comment

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

What would happen if we didn't suppress this - how much would it spread (propagating the attribute to affected public APIs).
The functionality will not work in single-file - so silencing it until it gets fixed is wrong. The warnings are there for this specific reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding [RequiresAssemblyFiles] in this function doesn't propagate to other places. I think is a limitation in the analyzer, because the attribute is on an override, but the methods call a virtual function in LicenseContext.cs
If propagated to the callers, then GetCurrentContextInfo uses LicenseUsageMode.Designtime and it's called by COM so it doesn't propagate more.
The other caller is GetLicense which uses LicenseUsageMode.Runtime, for me is uncertain if that will result in calling the override in DesigntimeLicenseContext. But that method has about 10 different call sites that would need to be annotated most of them in System.ComponentModel.LicenseManger.

Copy link
Member

Choose a reason for hiding this comment

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

and it's called by COM so it doesn't propagate more.

Well - it doesn't propagate in the analyzer - but functionally it does propagate - so this is the killer argument for me. It would basically mean we should potentially annotate the entire COM this way.

Regarding the analyzer: We should add a similar check to what RequiresUnreferencedCode has (at least in the linker) - that is, all methods in a virtual override chain should have the same annotations. So if an override has the attribute, the base method should have it as well, and vice-versa. If this is not the case, please file a bug for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I opened dotnet/linker#1985 to track work for virtual calls in the analyzers

public override string GetSavedLicenseKey(Type type, Assembly resourceAssembly)
{
if (_savedLicenseKeys == null || _savedLicenseKeys[type.AssemblyQualifiedName] == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,7 @@
<ItemGroup Condition="'$(IsPartialFacadeAssembly)' == 'true'">
<Reference Include="System.Configuration" />
</ItemGroup>
<ItemGroup>
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\UnconditionalSuppressMessageAttribute.cs" />
tlakollo marked this conversation as resolved.
Show resolved Hide resolved
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Reflection;
Expand All @@ -28,6 +29,8 @@ internal sealed class ClientConfigPaths
private readonly bool _includesUserConfig;
private string _companyName;

[UnconditionalSuppressMessage("Single file", "IL3000: Avoid accessing Assembly file path when publishing as a single file",
Justification = "Code handles single file case")]
private ClientConfigPaths(string exePath, bool includeUserConfig)
{
_includesUserConfig = includeUserConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Win32.Registry\src\Microsoft.Win32.Registry.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Threading.AccessControl\src\System.Threading.AccessControl.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != '$(NetCoreAppCurrent)-windows'">
tlakollo marked this conversation as resolved.
Show resolved Hide resolved
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\UnconditionalSuppressMessageAttribute.cs" />
</ItemGroup>

<!-- Ensure we run ResolveProjectReferences to add the message DLL to the package.
We do this here rather than in the pkgproj to ensure the package paths are in sync -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -691,6 +692,8 @@ internal static RegistryKey GetEventLogRegKey(string machine, bool writable)
return null;
}

[UnconditionalSuppressMessage("Single file", "IL3000: Avoid accessing Assembly file path when publishing as a single file",
Justification = "The code handles if the path is null by calling AppContext.BaseDirectory")]
internal static string GetDllPath(string machineName)
{
string dllPath = Path.Combine(NetFrameworkUtils.GetLatestBuildDllDirectory(machineName), DllName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Reflection;

namespace System
{
public static partial class AppContext
{
[UnconditionalSuppressMessage("Single file", "IL3000: Avoid accessing Assembly file path when publishing as a single file",
Justification = "Single File apps should always set APP_CONTEXT_BASE_DIRECTORY therefore code handles Assembly.Location equals null")]
private static string GetBaseDirectoryCore()
{
// Fallback path for hosts that do not set APP_CONTEXT_BASE_DIRECTORY explicitly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ namespace System.Diagnostics.CodeAnalysis
AttributeTargets.Property,
Inherited = false,
AllowMultiple = false)]
public sealed class RequiresAssemblyFilesAttribute : Attribute
#if SYSTEM_PRIVATE_CORELIB
public
#else
internal
#endif
sealed class RequiresAssemblyFilesAttribute : Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="RequiresAssemblyFilesAttribute"/> class.
Expand All @@ -32,4 +37,4 @@ public RequiresAssemblyFilesAttribute() { }
/// </summary>
public string? Url { get; set; }
}
}
}
Loading