本文整理汇总了C#中Microsoft.DotNet.ProjectModel.ProjectContext类的典型用法代码示例。如果您正苦于以下问题:C# ProjectContext类的具体用法?C# ProjectContext怎么用?C# ProjectContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProjectContext类属于Microsoft.DotNet.ProjectModel命名空间,在下文中一共展示了ProjectContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessContext
protected virtual void ProcessContext(ProjectContext context)
{
PopulateDependencies(context);
var inputFolder = ArtifactPathsCalculator.InputPathForContext(context);
var outputName = GetProjectOutputName(context.TargetFramework);
var resourceCultures = context.ProjectFile.Files.ResourceFiles
.Select(resourceFile => ResourceUtility.GetResourceCultureName(resourceFile.Key))
.Distinct();
foreach (var culture in resourceCultures)
{
if (string.IsNullOrEmpty(culture))
{
continue;
}
var resourceFilePath = Path.Combine(culture, $"{Project.Name}.resources.dll");
TryAddOutputFile(context, inputFolder, resourceFilePath);
}
TryAddOutputFile(context, inputFolder, outputName);
TryAddOutputFile(context, inputFolder, $"{Project.Name}.xml");
}
示例2: GetCompileIO
// computes all the inputs and outputs that would be used in the compilation of a project
// ensures that all paths are files
// ensures no missing inputs
public static CompilerIO GetCompileIO(ProjectContext project, string config, string outputPath, string intermediaryOutputPath, ProjectDependenciesFacade dependencies)
{
var compilerIO = new CompilerIO(new List<string>(), new List<string>());
var compilationOutput = CompilerUtil.GetCompilationOutput(project.ProjectFile, project.TargetFramework, config, outputPath);
// input: project.json
compilerIO.Inputs.Add(project.ProjectFile.ProjectFilePath);
// input: lock file; find when dependencies change
AddLockFile(project, compilerIO);
// input: source files
compilerIO.Inputs.AddRange(CompilerUtil.GetCompilationSources(project));
// todo: Factor out dependency resolution between Build and Compile. Ideally Build injects the dependencies into Compile
// input: dependencies
AddDependencies(dependencies, compilerIO);
// output: compiler output
compilerIO.Outputs.Add(compilationOutput);
// input / output: compilation options files
AddFilesFromCompilationOptions(project, config, compilationOutput, compilerIO);
// input / output: resources without culture
AddCultureResources(project, intermediaryOutputPath, compilerIO);
// input / output: resources with culture
AddNonCultureResources(project, outputPath, compilerIO);
return compilerIO;
}
示例3: ResolveCompilerName
public static string ResolveCompilerName(ProjectContext context)
{
var compilerName = context.ProjectFile.CompilerName;
compilerName = compilerName ?? "csc";
return compilerName;
}
示例4: InputPathForContext
public string InputPathForContext(ProjectContext context)
{
return Path.Combine(
CompiledArtifactsPath,
_configuration,
context.TargetFramework.GetTwoDigitShortFolderName());
}
示例5: CreateForProject
public static AssemblyInfoOptions CreateForProject(ProjectContext context)
{
var project = context.ProjectFile;
NuGetFramework targetFramework = null;
// force .NETFramework instead of DNX
if (context.TargetFramework.IsDesktop())
{
targetFramework = new NuGetFramework(FrameworkConstants.FrameworkIdentifiers.Net, context.TargetFramework.Version);
}
else
{
targetFramework = context.TargetFramework;
}
return new AssemblyInfoOptions()
{
AssemblyVersion = project.Version?.Version.ToString(),
AssemblyFileVersion = project.AssemblyFileVersion.ToString(),
InformationalVersion = project.Version.ToString(),
Copyright = project.Copyright,
Description = project.Description,
Title = project.Title,
NeutralLanguage = project.Language,
TargetFramework = targetFramework.DotNetFrameworkName
};
}
示例6: TraverseProject
private ProjectGraphNode TraverseProject(ProjectDescription project, IDictionary<string, LibraryDescription> lookup, ProjectContext context = null)
{
var isRoot = context != null;
var deps = new List<ProjectGraphNode>();
if (isRoot || _collectDependencies)
{
foreach (var dependency in project.Dependencies)
{
LibraryDescription libraryDescription;
if ((lookup.TryGetValue(dependency.Name, out libraryDescription)) && (!libraryDescription.Identity.Name.Equals(project.Identity.Name)))
{
if (libraryDescription.Resolved && libraryDescription.Identity.Type.Equals(LibraryType.Project))
{
deps.Add(TraverseProject((ProjectDescription)libraryDescription, lookup));
}
else
{
deps.AddRange(TraverseNonProject(libraryDescription, lookup));
}
}
}
}
var task = context != null ? Task.FromResult(context) : Task.Run(() => _projectContextFactory(project.Path, project.Framework));
return new ProjectGraphNode(task, deps, isRoot);
}
示例7: CalculateDefaultsForNonAssigned
private void CalculateDefaultsForNonAssigned()
{
if (string.IsNullOrWhiteSpace(Project))
{
Project = Directory.GetCurrentDirectory();
}
if (string.IsNullOrWhiteSpace(Configuration))
{
Configuration = Constants.DefaultConfiguration;
}
var contexts = ProjectContext.CreateContextForEachFramework(Project);
if (Framework == null)
{
_context = contexts.First();
}
else
{
var fx = NuGetFramework.Parse(Framework);
_context = contexts.FirstOrDefault(c => c.TargetFramework.Equals(fx));
}
if (Args == null)
{
_args = new List<string>();
}
else
{
_args = new List<string>(Args);
}
}
示例8: ResolveLanguageId
public static string ResolveLanguageId(ProjectContext context)
{
var languageId = context.ProjectFile.AnalyzerOptions?.LanguageId;
languageId = languageId ?? "cs";
return languageId;
}
示例9: GetRuntimeDependencies
private static IEnumerable<string> GetRuntimeDependencies(ProjectContext projectContext, string buildConfiguration)
{
// We collect the full list of runtime dependencies here and pass them back so they can be
// referenced by the REPL environment when seeding the context. It appears that we need to
// explicitly list the dependencies as they may not exist in the output directory (as is the
// for library projects) or they may not exist anywhere on the path (e.g. they may only exist
// in the nuget package that was downloaded for the compilation) or they may be specific to a
// specific target framework.
var runtimeDependencies = new HashSet<string>();
var projectExporter = projectContext.CreateExporter(buildConfiguration);
var projectDependencies = projectExporter.GetDependencies();
foreach (var projectDependency in projectDependencies)
{
var runtimeAssemblies = projectDependency.RuntimeAssemblies;
foreach (var runtimeAssembly in runtimeAssemblies)
{
var runtimeAssemblyPath = runtimeAssembly.ResolvedPath;
runtimeDependencies.Add(runtimeAssemblyPath);
}
}
return runtimeDependencies;
}
示例10: DoRunTests
internal override int DoRunTests(ProjectContext projectContext, DotnetTestParams dotnetTestParams)
{
Console.WriteLine("Listening on port {0}", dotnetTestParams.Port.Value);
HandleDesignTimeMessages(projectContext, dotnetTestParams);
return 0;
}
示例11: ProcessContext
protected override void ProcessContext(ProjectContext context)
{
base.ProcessContext(context);
var inputFolder = ArtifactPathsCalculator.InputPathForContext(context);
TryAddOutputFile(context, inputFolder, $"{Project.Name}.pdb");
TryAddOutputFile(context, inputFolder, $"{Project.Name}.mdb");
}
示例12: Executable
public Executable(ProjectContext context, OutputPaths outputPaths, LibraryExporter exporter)
{
_context = context;
_outputPaths = outputPaths;
_runtimeOutputPath = outputPaths.RuntimeOutputPath;
_intermediateOutputPath = outputPaths.IntermediateOutputDirectoryPath;
_exporter = exporter;
}
示例13: ProcessContext
protected override void ProcessContext(ProjectContext context)
{
base.ProcessContext(context);
var outputPath = GetOutputPath(context);
TryAddOutputFile(context, outputPath, $"{Project.Name}.pdb");
TryAddOutputFile(context, outputPath, $"{Project.Name}.mdb");
}
示例14: AddProject
private ProjectId AddProject(ProjectContext project)
{
// Create the framework specific project and add it to the workspace
var projectInfo = ProjectInfo.Create(
ProjectId.CreateNewId(),
VersionStamp.Create(),
project.ProjectFile.Name + "+" + project.TargetFramework,
project.ProjectFile.Name,
LanguageNames.CSharp,
project.ProjectFile.ProjectFilePath);
OnProjectAdded(projectInfo);
// TODO: ctor argument?
var configuration = "Debug";
var compilationOptions = project.ProjectFile.GetCompilerOptions(project.TargetFramework, configuration);
var compilationSettings = ToCompilationSettings(compilationOptions, project.TargetFramework, project.ProjectFile.ProjectDirectory);
OnParseOptionsChanged(projectInfo.Id, new CSharpParseOptions(compilationSettings.LanguageVersion, preprocessorSymbols: compilationSettings.Defines));
OnCompilationOptionsChanged(projectInfo.Id, compilationSettings.CompilationOptions);
foreach (var file in project.ProjectFile.Files.SourceFiles)
{
AddSourceFile(projectInfo, file);
}
var exporter = project.CreateExporter(configuration);
foreach (var dependency in exporter.GetDependencies())
{
var projectDependency = dependency.Library as ProjectDescription;
if (projectDependency != null)
{
var projectDependencyContext = ProjectContext.Create(projectDependency.Project.ProjectFilePath, projectDependency.Framework);
var id = AddProject(projectDependencyContext);
OnProjectReferenceAdded(projectInfo.Id, new ProjectReference(id));
}
else
{
foreach (var asset in dependency.CompilationAssemblies)
{
OnMetadataReferenceAdded(projectInfo.Id, GetMetadataReference(asset.ResolvedPath));
}
}
foreach (var file in dependency.SourceReferences)
{
AddSourceFile(projectInfo, file);
}
}
return projectInfo.Id;
}
示例15: Compile
public bool Compile(ProjectContext context, string config, string probingFolderPath)
{
var compilationlock = _compilationlocks.GetOrAdd(context.ProjectName(), id => new object());
lock (compilationlock)
{
return CompileInternal(context, config, probingFolderPath);
}
}