|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Text.Json;
namespace Microsoft.DotNet.Cli.Commands.Run;
// Generated by test `RunFileTests.CscArguments`.
partial class CSharpCompilerCommand
{
private IEnumerable<string> GetCscArguments(
string objDir,
string binDir)
{
return
[
"/unsafe-",
"/checked-",
"/nowarn:1701,1702,IL2121,1701,1702,8002",
"/fullpaths",
"/nostdlib+",
"/errorreport:prompt",
"/warn:11",
"/define:TRACE;DEBUG;NET;NET11_0;NETCOREAPP;NET5_0_OR_GREATER;NET6_0_OR_GREATER;NET7_0_OR_GREATER;NET8_0_OR_GREATER;NET9_0_OR_GREATER;NET10_0_OR_GREATER;NET11_0_OR_GREATER;NETCOREAPP1_0_OR_GREATER;NETCOREAPP1_1_OR_GREATER;NETCOREAPP2_0_OR_GREATER;NETCOREAPP2_1_OR_GREATER;NETCOREAPP2_2_OR_GREATER;NETCOREAPP3_0_OR_GREATER;NETCOREAPP3_1_OR_GREATER",
"/highentropyva+",
"/nullable:enable",
.. GetFrameworkReferenceArguments(),
"/features:InterceptorsNamespaces=;Microsoft.AspNetCore.Http.Generated;Microsoft.Extensions.Configuration.Binder.SourceGeneration;Microsoft.Extensions.Validation.Generated",
"/debug+",
"/debug:portable",
"/filealign:512",
"/optimize-",
$"/out:{binDir}/{FileNameWithoutExtension}.dll",
"/target:exe",
"/warnaserror-",
"/utf8output",
"/deterministic+",
"/langversion:14.0",
"/features:FileBasedProgram",
$"/analyzerconfig:{SdkPath}/Sdks/Microsoft.NET.Sdk/codestyle/cs/build/config/analysislevelstyle_default.globalconfig",
$"/analyzerconfig:{objDir}/{FileName}.GeneratedMSBuildEditorConfig.editorconfig",
$"/analyzerconfig:{SdkPath}/Sdks/Microsoft.NET.Sdk/analyzers/build/config/analysislevel_11_default.globalconfig",
$"/analyzer:{SdkPath}/Sdks/Microsoft.NET.Sdk/targets/../analyzers/Microsoft.CodeAnalysis.CSharp.NetAnalyzers.dll",
$"/analyzer:{SdkPath}/Sdks/Microsoft.NET.Sdk/targets/../analyzers/Microsoft.CodeAnalysis.NetAnalyzers.dll",
$"/analyzer:{NuGetCachePath}/microsoft.net.illink.tasks/{RuntimeVersion}/analyzers/dotnet/cs/ILLink.CodeFixProvider.dll",
$"/analyzer:{NuGetCachePath}/microsoft.net.illink.tasks/{RuntimeVersion}/analyzers/dotnet/cs/ILLink.RoslynAnalyzer.dll",
.. GetFrameworkAnalyzerArguments(),
$"{EntryPointFileFullPath}",
$"{objDir}/{FileName}.GlobalUsings.g.cs",
$"{objDir}/.NETCoreApp,Version=v{TargetFrameworkVersion}.AssemblyAttributes.cs",
$"{objDir}/{FileName}.AssemblyInfo.cs",
"/warnaserror+:NU1605,SYSLIB0011",
];
}
/// <summary>
/// Files that come from referenced NuGet packages (e.g., analyzers for NativeAOT) need to be checked specially (if they don't exist, MSBuild needs to run).
/// </summary>
public static IEnumerable<string> GetPathsOfCscInputsFromNuGetCache()
{
return
[
$"{NuGetCachePath}/microsoft.net.illink.tasks/{RuntimeVersion}/analyzers/dotnet/cs/ILLink.CodeFixProvider.dll",
$"{NuGetCachePath}/microsoft.net.illink.tasks/{RuntimeVersion}/analyzers/dotnet/cs/ILLink.RoslynAnalyzer.dll",
];
}
private string GetRuntimeConfigContent()
{
return $$"""
{
"runtimeOptions": {
"tfm": {{JsonSerializer.Serialize(TargetFramework, CSharpCompilerCommandJsonSerializerContext.Default.String)}},
"framework": {
"name": "Microsoft.NETCore.App",
"version": {{JsonSerializer.Serialize(DefaultRuntimeVersion, CSharpCompilerCommandJsonSerializerContext.Default.String)}}
},
"configProperties": {
"EntryPointFilePath": {{JsonSerializer.Serialize(EntryPointFileFullPath, CSharpCompilerCommandJsonSerializerContext.Default.String)}},
"EntryPointFileDirectoryPath": {{JsonSerializer.Serialize(BaseDirectory, CSharpCompilerCommandJsonSerializerContext.Default.String)}},
"Microsoft.Extensions.DependencyInjection.VerifyOpenGenericServiceTrimmability": true,
"System.ComponentModel.DefaultValueAttribute.IsSupported": false,
"System.ComponentModel.Design.IDesignerHost.IsSupported": false,
"System.ComponentModel.TypeConverter.EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization": false,
"System.ComponentModel.TypeDescriptor.IsComObjectDescriptorSupported": false,
"System.Data.DataSet.XmlSerializationIsSupported": false,
"System.Diagnostics.Tracing.EventSource.IsSupported": false,
"System.Linq.Enumerable.IsSizeOptimized": true,
"System.Net.SocketsHttpHandler.Http3Support": false,
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
"System.Resources.ResourceManager.AllowCustomResourceTypes": false,
"System.Resources.UseSystemResourceKeys": false,
"System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported": false,
"System.Runtime.InteropServices.BuiltInComInterop.IsSupported": false,
"System.Runtime.InteropServices.EnableConsumingManagedCodeFromNativeHosting": false,
"System.Runtime.InteropServices.EnableCppCLIHostActivation": false,
"System.Runtime.InteropServices.Marshalling.EnableGeneratedComInterfaceComImportInterop": false,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false,
"System.StartupHookProvider.IsSupported": false,
"System.Text.Encoding.EnableUnsafeUTF7Encoding": false,
"System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault": false,
"System.Threading.Thread.EnableAutoreleasePool": false,
"System.Linq.Expressions.CanEmitObjectArrayDelegate": false
}
}
}
""";
}
private string GetAssemblyAttributesContent()
{
return $"""
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v{TargetFrameworkVersion}", FrameworkDisplayName = ".NET {TargetFrameworkVersion}")]
""";
}
private string GetAssemblyInfoContent()
{
return $"""
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("{FileNameWithoutExtension}")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("{FileNameWithoutExtension}")]
[assembly: System.Reflection.AssemblyTitleAttribute("{FileNameWithoutExtension}")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.
""";
}
private string GetGeneratedMSBuildEditorConfigContent()
{
return $"""
is_global = true
build_property.EnableAotAnalyzer = true
build_property.EnableSingleFileAnalyzer = true
build_property.EnableTrimAnalyzer = true
build_property.EnableUnsafeAnalyzer =
build_property.IncludeAllContentForSelfExtract =
build_property.VerifyReferenceTrimCompatibility =
build_property.VerifyReferenceAotCompatibility =
build_property.TargetFramework = net{TargetFrameworkVersion}
build_property.TargetFrameworkIdentifier = .NETCoreApp
build_property.TargetFrameworkVersion = v{TargetFrameworkVersion}
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property.EntryPointFilePath = {EntryPointFileFullPath}
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = {FileNameWithoutExtension}
build_property.ProjectDir = {BaseDirectoryWithTrailingSeparator}
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop = false
build_property.EffectiveAnalysisLevelStyle = {TargetFrameworkVersion}
build_property.EnableCodeStyleSeverity =
""";
}
private string GetGlobalUsingsContent()
{
return """
// <auto-generated/>
global using System;
global using System.Collections.Generic;
global using System.IO;
global using System.Linq;
global using System.Net.Http;
global using System.Net.Http.Json;
global using System.Threading;
global using System.Threading.Tasks;
""";
}
}
|