本文整理汇总了C#中Microsoft.DotNet.ProjectModel.ProjectContext.ResolveCompilationOptions方法的典型用法代码示例。如果您正苦于以下问题:C# ProjectContext.ResolveCompilationOptions方法的具体用法?C# ProjectContext.ResolveCompilationOptions怎么用?C# ProjectContext.ResolveCompilationOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.DotNet.ProjectModel.ProjectContext
的用法示例。
在下文中一共展示了ProjectContext.ResolveCompilationOptions方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Compile
public override bool Compile(ProjectContext context, BuildCommandApp args)
{
// Set up Output Paths
var outputPaths = context.GetOutputPaths(args.ConfigValue, args.BuildBasePathValue);
var outputPath = outputPaths.CompilationOutputPath;
var intermediateOutputPath = outputPaths.IntermediateOutputDirectoryPath;
Directory.CreateDirectory(outputPath);
Directory.CreateDirectory(intermediateOutputPath);
// Create the library exporter
var exporter = context.CreateExporter(args.ConfigValue, args.BuildBasePathValue);
// Gather exports for the project
var dependencies = exporter.GetDependencies().ToList();
Reporter.Output.WriteLine($"Compiling {context.RootProject.Identity.Name.Yellow()} for {context.TargetFramework.DotNetFrameworkName.Yellow()}");
var sw = Stopwatch.StartNew();
var diagnostics = new List<DiagnosticMessage>();
var missingFrameworkDiagnostics = new List<DiagnosticMessage>();
// Collect dependency diagnostics
foreach (var diag in context.LibraryManager.GetAllDiagnostics())
{
if (diag.ErrorCode == ErrorCodes.DOTNET1011 ||
diag.ErrorCode == ErrorCodes.DOTNET1012)
{
missingFrameworkDiagnostics.Add(diag);
}
diagnostics.Add(diag);
}
if(diagnostics.Any(d => d.Severity == DiagnosticMessageSeverity.Error))
{
// We got an unresolved dependency or missing framework. Don't continue the compilation.
PrintSummary(diagnostics, sw);
return false;
}
// Get compilation options
var outputName = outputPaths.CompilationFiles.Assembly;
// Assemble args
var compilerArgs = new List<string>()
{
$"--temp-output:{intermediateOutputPath}",
$"--out:{outputName}"
};
var compilationOptions = context.ResolveCompilationOptions(args.ConfigValue);
// Set default platform if it isn't already set and we're on desktop
if (compilationOptions.EmitEntryPoint == true && string.IsNullOrEmpty(compilationOptions.Platform) && context.TargetFramework.IsDesktop())
{
// See https://github.com/dotnet/cli/issues/2428 for more details.
compilationOptions.Platform = RuntimeInformation.ProcessArchitecture == Architecture.X64 ?
"x64" : "anycpu32bitpreferred";
}
var languageId = CompilerUtil.ResolveLanguageId(context);
var references = new List<string>();
// Add compilation options to the args
compilerArgs.AddRange(compilationOptions.SerializeToArgs());
// Add metadata options
compilerArgs.AddRange(AssemblyInfoOptions.SerializeToArgs(AssemblyInfoOptions.CreateForProject(context)));
foreach (var dependency in dependencies)
{
references.AddRange(dependency.CompilationAssemblies.Select(r => r.ResolvedPath));
compilerArgs.AddRange(dependency.SourceReferences.Select(s => s.GetTransformedFile(intermediateOutputPath)));
foreach (var resourceFile in dependency.EmbeddedResources)
{
var transformedResource = resourceFile.GetTransformedFile(intermediateOutputPath);
var resourceName = ResourceManifestName.CreateManifestName(
Path.GetFileName(resourceFile.ResolvedPath), compilationOptions.OutputName);
compilerArgs.Add($"--resource:\"{transformedResource}\",{resourceName}");
}
// Add analyzer references
compilerArgs.AddRange(dependency.AnalyzerReferences
.Where(a => a.AnalyzerLanguage == languageId)
.Select(a => $"--analyzer:{a.AssemblyPath}"));
}
compilerArgs.AddRange(references.Select(r => $"--reference:{r}"));
if (compilationOptions.PreserveCompilationContext == true)
{
var allExports = exporter.GetAllExports().ToList();
var exportsLookup = allExports.ToDictionary(e => e.Library.Identity.Name);
var buildExclusionList = context.GetTypeBuildExclusionList(exportsLookup);
var filteredExports = allExports
.Where(e => e.Library.Identity.Type.Equals(LibraryType.ReferenceAssembly) ||
//.........这里部分代码省略.........
示例2: IsDynamicContext
private bool IsDynamicContext(ProjectContext context)
{
var compilationOptions = context.ResolveCompilationOptions(Configuration);
return CompilerUtility.GetCompilationSources(context, compilationOptions).Any();
}
示例3: Compile
public override bool Compile(ProjectContext context, CompilerCommandApp args)
{
// Set up Output Paths
var outputPaths = context.GetOutputPaths(args.ConfigValue, args.BuildBasePathValue);
var outputPath = outputPaths.CompilationOutputPath;
var intermediateOutputPath = outputPaths.IntermediateOutputDirectoryPath;
Directory.CreateDirectory(outputPath);
Directory.CreateDirectory(intermediateOutputPath);
// Create the library exporter
var exporter = context.CreateExporter(args.ConfigValue, args.BuildBasePathValue);
// Gather exports for the project
var dependencies = exporter.GetDependencies().ToList();
Reporter.Output.WriteLine($"Compiling {context.RootProject.Identity.Name.Yellow()} for {context.TargetFramework.DotNetFrameworkName.Yellow()}");
var sw = Stopwatch.StartNew();
var diagnostics = new List<DiagnosticMessage>();
var missingFrameworkDiagnostics = new List<DiagnosticMessage>();
// Collect dependency diagnostics
foreach (var diag in context.LibraryManager.GetAllDiagnostics())
{
if (diag.ErrorCode == ErrorCodes.DOTNET1011 ||
diag.ErrorCode == ErrorCodes.DOTNET1012)
{
missingFrameworkDiagnostics.Add(diag);
}
diagnostics.Add(diag);
}
if (missingFrameworkDiagnostics.Count > 0)
{
// The framework isn't installed so we should short circuit the rest of the compilation
// so we don't get flooded with errors
PrintSummary(missingFrameworkDiagnostics, sw);
return false;
}
// Get compilation options
var outputName = outputPaths.CompilationFiles.Assembly;
// Assemble args
var compilerArgs = new List<string>()
{
$"--temp-output:{intermediateOutputPath}",
$"--out:{outputName}"
};
var compilationOptions = context.ResolveCompilationOptions(args.ConfigValue);
var languageId = CompilerUtil.ResolveLanguageId(context);
var references = new List<string>();
// Add compilation options to the args
compilerArgs.AddRange(compilationOptions.SerializeToArgs());
// Add metadata options
compilerArgs.AddRange(AssemblyInfoOptions.SerializeToArgs(AssemblyInfoOptions.CreateForProject(context)));
foreach (var dependency in dependencies)
{
references.AddRange(dependency.CompilationAssemblies.Select(r => r.ResolvedPath));
compilerArgs.AddRange(dependency.SourceReferences.Select(s => s.GetTransformedFile(intermediateOutputPath)));
foreach (var resourceFile in dependency.EmbeddedResources)
{
var transformedResource = resourceFile.GetTransformedFile(intermediateOutputPath);
var resourceName = ResourceManifestName.CreateManifestName(
Path.GetFileName(resourceFile.ResolvedPath), compilationOptions.OutputName);
compilerArgs.Add($"--resource:\"{transformedResource}\",{resourceName}");
}
// Add analyzer references
compilerArgs.AddRange(dependency.AnalyzerReferences
.Where(a => a.AnalyzerLanguage == languageId)
.Select(a => $"--analyzer:{a.AssemblyPath}"));
}
compilerArgs.AddRange(references.Select(r => $"--reference:{r}"));
if (compilationOptions.PreserveCompilationContext == true)
{
var allExports = exporter.GetAllExports().ToList();
var dependencyContext = new DependencyContextBuilder().Build(compilationOptions,
allExports,
allExports,
false, // For now, just assume non-portable mode in the legacy deps file (this is going away soon anyway)
context.TargetFramework,
context.RuntimeIdentifier ?? string.Empty);
var writer = new DependencyContextWriter();
var depsJsonFile = Path.Combine(intermediateOutputPath, compilationOptions.OutputName + "dotnet-compile.deps.json");
using (var fileStream = File.Create(depsJsonFile))
{
writer.Write(dependencyContext, fileStream);
//.........这里部分代码省略.........
示例4: CompileInternal
internal bool CompileInternal(ProjectContext context, string config, string probingFolderPath)
{
// Check if ambient library
if (AmbientLibraries.Contains(context.ProjectName()))
{
return true;
}
bool compilationResult;
// Check if already compiled
if (_compiledLibraries.TryGetValue(context.ProjectName(), out compilationResult))
{
return compilationResult;
}
// Get compilation options and source files
var compilationOptions = context.ResolveCompilationOptions(config);
var projectSourceFiles = CompilerUtility.GetCompilationSources(context, compilationOptions);
// Check if precompiled
if (!projectSourceFiles.Any())
{
return _compiledLibraries[context.ProjectName()] = true;
}
// Set up Output Paths
var outputPaths = context.GetOutputPaths(config);
var outputPath = outputPaths.CompilationOutputPath;
var intermediateOutputPath = outputPaths.IntermediateOutputDirectoryPath;
Directory.CreateDirectory(outputPath);
Directory.CreateDirectory(intermediateOutputPath);
// Create the library exporter
var exporter = context.CreateExporter(config);
// Gather exports for the project
var dependencies = exporter.GetDependencies().ToList();
// Get compilation options
var outputName = outputPaths.CompilationFiles.Assembly;
// Set default platform if it isn't already set and we're on desktop
if (compilationOptions.EmitEntryPoint == true && String.IsNullOrEmpty(compilationOptions.Platform) && context.TargetFramework.IsDesktop())
{
// See https://github.com/dotnet/cli/issues/2428 for more details.
compilationOptions.Platform = RuntimeInformation.ProcessArchitecture == Architecture.X64 ?
"x64" : "anycpu32bitpreferred";
}
var references = new List<string>();
var sourceFiles = new List<string>();
var resources = new List<string>();
// Get the runtime directory
var runtimeDirectory = Path.GetDirectoryName(EntryAssembly.Location);
foreach (var dependency in dependencies)
{
sourceFiles.AddRange(dependency.SourceReferences.Select(s => s.GetTransformedFile(intermediateOutputPath)));
foreach (var resourceFile in dependency.EmbeddedResources)
{
var transformedResource = resourceFile.GetTransformedFile(intermediateOutputPath);
var resourceName = ResourceManifestName.CreateManifestName(
Path.GetFileName(resourceFile.ResolvedPath), compilationOptions.OutputName);
resources.Add($"\"{transformedResource}\",{resourceName}");
}
var library = dependency.Library as ProjectDescription;
var package = dependency.Library as PackageDescription;
// Compile other referenced libraries
if (library != null && !AmbientLibraries.Contains(library.Identity.Name) && dependency.CompilationAssemblies.Any())
{
if (!_compiledLibraries.ContainsKey(library.Identity.Name))
{
var projectContext = GetProjectContextFromPath(library.Project.ProjectDirectory);
if (projectContext != null)
{
// Right now, if !success we try to use the last build
var success = Compile(projectContext, config, probingFolderPath);
}
}
}
// Check for an unresolved library
if (library != null && !library.Resolved)
{
var fileName = GetAssemblyFileName(library.Identity.Name);
// Search in the runtime directory
var path = Path.Combine(runtimeDirectory, fileName);
if (!File.Exists(path))
{
// Fallback to the project output path or probing folder
path = ResolveAssetPath(outputPath, probingFolderPath, fileName);
//.........这里部分代码省略.........
示例5: AddCompilationOptions
private static void AddCompilationOptions(ProjectContext project, string config, CompilerIO compilerIO)
{
var compilerOptions = project.ResolveCompilationOptions(config);
// input: key file
if (compilerOptions.KeyFile != null)
{
compilerIO.Inputs.Add(compilerOptions.KeyFile);
}
}
示例6: Compile
public bool Compile(ProjectContext context, string config, string buildBasePath)
{
// Set up Output Paths
var outputPaths = context.GetOutputPaths(config, buildBasePath);
var outputPath = outputPaths.CompilationOutputPath;
var intermediateOutputPath = outputPaths.IntermediateOutputDirectoryPath;
Directory.CreateDirectory(outputPath);
Directory.CreateDirectory(intermediateOutputPath);
// Create the library exporter
var exporter = context.CreateExporter(config, buildBasePath);
// Gather exports for the project
var dependencies = exporter.GetDependencies().ToList();
var diagnostics = new List<DiagnosticMessage>();
var missingFrameworkDiagnostics = new List<DiagnosticMessage>();
// Collect dependency diagnostics
foreach (var diag in context.LibraryManager.GetAllDiagnostics())
{
if (diag.ErrorCode == ErrorCodes.DOTNET1011 ||
diag.ErrorCode == ErrorCodes.DOTNET1012)
{
missingFrameworkDiagnostics.Add(diag);
}
diagnostics.Add(diag);
}
if(diagnostics.Any(d => d.Severity == DiagnosticMessageSeverity.Error))
{
// We got an unresolved dependency or missing framework. Don't continue the compilation.
return false;
}
// Get compilation options
var outputName = outputPaths.CompilationFiles.Assembly;
var compilationOptions = context.ResolveCompilationOptions(config);
// Set default platform if it isn't already set and we're on desktop
if (compilationOptions.EmitEntryPoint == true && string.IsNullOrEmpty(compilationOptions.Platform) && context.TargetFramework.IsDesktop())
{
// See https://github.com/dotnet/cli/issues/2428 for more details.
compilationOptions.Platform = RuntimeInformation.ProcessArchitecture == Architecture.X64 ?
"x64" : "anycpu32bitpreferred";
}
var references = new List<string>();
var sourceFiles = new List<string>();
// Add metadata options
var assemblyInfoOptions = AssemblyInfoOptions.CreateForProject(context);
foreach (var dependency in dependencies)
{
references.AddRange(dependency.CompilationAssemblies.Select(r => r.ResolvedPath));
sourceFiles.AddRange(dependency.SourceReferences.Select(s => s.GetTransformedFile(intermediateOutputPath)));
}
var resources = new List<string>();
if (compilationOptions.PreserveCompilationContext == true)
{
var allExports = exporter.GetAllExports().ToList();
var dependencyContext = new DependencyContextBuilder().Build(compilationOptions,
allExports,
allExports,
false, // For now, just assume non-portable mode in the legacy deps file (this is going away soon anyway)
context.TargetFramework,
context.RuntimeIdentifier ?? string.Empty);
var writer = new DependencyContextWriter();
var depsJsonFile = Path.Combine(intermediateOutputPath, compilationOptions.OutputName + "dotnet-compile.deps.json");
using (var fileStream = File.Create(depsJsonFile))
{
writer.Write(dependencyContext, fileStream);
}
resources.Add($"\"{depsJsonFile}\",{compilationOptions.OutputName}.deps.json");
}
// Add project source files
if (compilationOptions.CompileInclude == null)
{
sourceFiles.AddRange(context.ProjectFile.Files.SourceFiles);
}
else {
var includeFiles = IncludeFilesResolver.GetIncludeFiles(compilationOptions.CompileInclude, "/", diagnostics: null);
sourceFiles.AddRange(includeFiles.Select(f => f.SourcePath));
}
if (String.IsNullOrEmpty(intermediateOutputPath))
{
return false;
}
var translated = TranslateCommonOptions(compilationOptions, outputName);
var allArgs = new List<string>(translated);
//.........这里部分代码省略.........