本文整理汇总了C#中Microsoft.DotNet.ProjectModel.ProjectContext.GetTypeBuildExclusionList方法的典型用法代码示例。如果您正苦于以下问题:C# ProjectContext.GetTypeBuildExclusionList方法的具体用法?C# ProjectContext.GetTypeBuildExclusionList怎么用?C# ProjectContext.GetTypeBuildExclusionList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.DotNet.ProjectModel.ProjectContext
的用法示例。
在下文中一共展示了ProjectContext.GetTypeBuildExclusionList方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompileInternal
//.........这里部分代码省略.........
references.Add(path);
}
}
}
// Check for a resolved but ambient library (compiled e.g by VS)
else if (library != null && AmbientLibraries.Contains(library.Identity.Name))
{
// Search in the regular project bin folder, fallback to the runtime directory
references.AddRange(dependency.CompilationAssemblies.Select(r => File.Exists(r.ResolvedPath)
? r.ResolvedPath : Path.Combine(runtimeDirectory, r.FileName)));
}
else
{
references.AddRange(dependency.CompilationAssemblies.Select(r => r.ResolvedPath));
}
}
// Check again if already compiled, here through the dependency graph
if (_compiledLibraries.TryGetValue(context.ProjectName(), out compilationResult))
{
return compilationResult;
}
var sw = Stopwatch.StartNew();
string depsJsonFile = null;
DependencyContext dependencyContext = null;
// Add dependency context as a resource
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) ||
!buildExclusionList.Contains(e.Library.Identity.Name));
dependencyContext = new DependencyContextBuilder().Build(compilationOptions,
filteredExports,
filteredExports,
false, // For now, just assume non-portable mode in the legacy deps file (this is going away soon anyway)
context.TargetFramework,
depsJsonFile = Path.Combine(intermediateOutputPath, compilationOptions.OutputName + "dotnet-compile.deps.json"));
resources.Add($"\"{depsJsonFile}\",{compilationOptions.OutputName}.deps.json");
}
// Add project source files
sourceFiles.AddRange(projectSourceFiles);
// Add non culture resources
var resgenFiles = CompilerUtility.GetNonCultureResources(context.ProjectFile, intermediateOutputPath, compilationOptions);
AddNonCultureResources(resources, resgenFiles);
var translated = TranslateCommonOptions(compilationOptions, outputName);
var allArgs = new List<string>(translated);
allArgs.AddRange(GetDefaultOptions());
// Add assembly info
var assemblyInfo = Path.Combine(intermediateOutputPath, $"dotnet-compile.assemblyinfo.cs");
allArgs.Add($"\"{assemblyInfo}\"");
if (!String.IsNullOrEmpty(outputName))
{
示例2: 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) ||
//.........这里部分代码省略.........
示例3: PublishProjectContext
/// <summary>
/// Publish the project for given 'framework (ex - netcoreapp1.0)' and 'runtimeID (ex - win7-x64)'
/// </summary>
/// <param name="context">project that is to be published</param>
/// <param name="baseOutputPath">Location of published files</param>
/// <param name="configuration">Debug or Release</param>
/// <param name="nativeSubdirectories"></param>
/// <returns>Return 0 if successful else return non-zero</returns>
private bool PublishProjectContext(ProjectContext context, string buildBasePath, string outputPath, string configuration, bool nativeSubdirectories)
{
var target = context.TargetFramework.DotNetFrameworkName;
if (!string.IsNullOrEmpty(context.RuntimeIdentifier))
{
target = $"{target}/{context.RuntimeIdentifier}";
}
Reporter.Output.WriteLine($"Publishing {context.RootProject.Identity.Name.Yellow()} for {target.Yellow()}");
var options = context.ProjectFile.GetCompilerOptions(context.TargetFramework, configuration);
var outputPaths = context.GetOutputPaths(configuration, buildBasePath, outputPath);
if (string.IsNullOrEmpty(outputPath))
{
outputPath = Path.Combine(outputPaths.RuntimeOutputPath, PublishSubfolderName);
}
var contextVariables = new Dictionary<string, string>
{
{ "publish:ProjectPath", context.ProjectDirectory },
{ "publish:Configuration", configuration },
{ "publish:OutputPath", outputPath },
{ "publish:TargetFramework", context.TargetFramework.GetShortFolderName() },
{ "publish:FullTargetFramework", context.TargetFramework.DotNetFrameworkName },
{ "publish:Runtime", context.RuntimeIdentifier },
};
RunScripts(context, ScriptNames.PrePublish, contextVariables);
if (!Directory.Exists(outputPath))
{
Directory.CreateDirectory(outputPath);
}
// Compile the project (and transitively, all it's dependencies)
if (ShouldBuild && !InvokeBuildOnProject(context, buildBasePath, configuration))
{
return false;
}
// Use a library exporter to collect publish assets
var exporter = context.CreateExporter(configuration, buildBasePath);
// Get the output paths used by the call to `dotnet build` above (since we didn't pass `--output`, they will be different from
// our current output paths)
var buildOutputPaths = context.GetOutputPaths(configuration, buildBasePath);
var exports = exporter.GetAllExports();
var exportsLookup = exports.ToDictionary(e => e.Library.Identity.Name);
var platformExclusionList = context.GetPlatformExclusionList(exportsLookup);
var buildExclusionList = context.GetTypeBuildExclusionList(exportsLookup);
var allExclusionList = new HashSet<string>(platformExclusionList);
allExclusionList.UnionWith(buildExclusionList);
var filteredExports = exports.FilterExports(allExclusionList);
foreach (var export in filteredExports)
{
Reporter.Verbose.WriteLine($"publish: Publishing {export.Library.Identity.ToString().Green().Bold()} ...");
PublishAssetGroups(export.RuntimeAssemblyGroups, outputPath, nativeSubdirectories: false, includeRuntimeGroups: context.IsPortable);
PublishAssetGroups(export.NativeLibraryGroups, outputPath, nativeSubdirectories, includeRuntimeGroups: context.IsPortable);
var runtimeAssetsToCopy = export.RuntimeAssets.Where(a => ShouldCopyExportRuntimeAsset(context, buildOutputPaths, export, a));
runtimeAssetsToCopy.StructuredCopyTo(outputPath, outputPaths.IntermediateOutputDirectoryPath);
foreach (var resourceAsset in export.ResourceAssemblies)
{
var dir = Path.Combine(outputPath, resourceAsset.Locale);
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
File.Copy(resourceAsset.Asset.ResolvedPath, Path.Combine(dir, resourceAsset.Asset.FileName), overwrite: true);
}
}
foreach (var export in exports)
{
if (options.PreserveCompilationContext.GetValueOrDefault())
{
PublishRefs(export, outputPath);
}
}
if (context.ProjectFile.HasRuntimeOutput(configuration) && !context.TargetFramework.IsDesktop())
{
// Make executable in the new location
var executable = new Executable(context, buildOutputPaths, outputPath, buildOutputPaths.IntermediateOutputDirectoryPath, exporter, configuration);
var runtimeExports = filteredExports;
var compilationExports = exports.FilterExports(buildExclusionList);
executable.WriteConfigurationFiles(exports, runtimeExports, compilationExports, includeDevConfig: false);
//.........这里部分代码省略.........