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"); }
// 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; }
public static string ResolveCompilerName(ProjectContext context) { var compilerName = context.ProjectFile.CompilerName; compilerName = compilerName ?? "csc"; return compilerName; }
public string InputPathForContext(ProjectContext context) { return Path.Combine( CompiledArtifactsPath, _configuration, context.TargetFramework.GetTwoDigitShortFolderName()); }
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 }; }
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); }
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); } }
public static string ResolveLanguageId(ProjectContext context) { var languageId = context.ProjectFile.AnalyzerOptions?.LanguageId; languageId = languageId ?? "cs"; return languageId; }
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; }
internal override int DoRunTests(ProjectContext projectContext, DotnetTestParams dotnetTestParams) { Console.WriteLine("Listening on port {0}", dotnetTestParams.Port.Value); HandleDesignTimeMessages(projectContext, dotnetTestParams); return 0; }
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"); }
public Executable(ProjectContext context, OutputPaths outputPaths, LibraryExporter exporter) { _context = context; _outputPaths = outputPaths; _runtimeOutputPath = outputPaths.RuntimeOutputPath; _intermediateOutputPath = outputPaths.IntermediateOutputDirectoryPath; _exporter = exporter; }
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"); }
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; }
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); } }
public static DependencyInfo Create(ProjectContext context, LibraryDescription library) { return new DependencyInfo { ProjectPath = context.ProjectFile.ProjectFilePath, Version = library.Identity.Version.ToString(), Name = library.Identity.Name }; }
private int BuildTestProject(ProjectContext projectContext, DotnetTestParams dotnetTestParams, BuildWorkspace workspace) { if (dotnetTestParams.NoBuild) { return 0; } return DoBuildTestProject(projectContext, dotnetTestParams, workspace); }
public Executable(ProjectContext context, OutputPaths outputPaths, LibraryExporter exporter, string configuration) { _context = context; _outputPaths = outputPaths; _runtimeOutputPath = outputPaths.RuntimeOutputPath; _intermediateOutputPath = outputPaths.IntermediateOutputDirectoryPath; _exporter = exporter; _compilerOptions = _context.ProjectFile.GetCompilerOptions(_context.TargetFramework, configuration); }
public static string ResolveLanguageId(ProjectContext context) { var languageId = context.ProjectFile.AnalyzerOptions?.LanguageId; if (languageId == null) { languageId = context.ProjectFile.GetSourceCodeLanguage(); } return languageId; }
protected override void ProcessContext(ProjectContext context) { base.ProcessContext(context); var inputFolder = ArtifactPathsCalculator.InputPathForContext(context); var ouptutName = Project.GetCompilerOptions(context.TargetFramework, Configuration).OutputName; TryAddOutputFile(context, inputFolder, $"{ouptutName}.pdb"); TryAddOutputFile(context, inputFolder, $"{ouptutName}.mdb"); }
// todo make extension of ProjectContext? private static List<LibraryExport> GetProjectDependencies(ProjectContext projectContext, string configuration) { // Create the library exporter var exporter = projectContext.CreateExporter(configuration); // Gather exports for the project var dependencies = exporter.GetDependencies().ToList(); return dependencies; }
public string InputPathForContext(ProjectContext context) { return OutputPathsCalculator.GetOutputPaths(context.ProjectFile, context.TargetFramework, context.RuntimeIdentifier, _configuration, context.RootDirectory, CompiledArtifactsPathParameter, null).CompilationOutputPath; }
public void RunScripts(ProjectContext context, string name, Dictionary<string, string> contextVariables) { foreach (var script in context.ProjectFile.Scripts.GetOrEmpty(name)) { ScriptExecutor.CreateCommandForScript(context.ProjectFile, script, contextVariables) .ForwardStdErr() .ForwardStdOut() .Execute(); } }
public static void PopulateDependencies(ProjectContext context, PackageBuilder packageBuilder) { var dependencies = new List<PackageDependency>(); var project = context.RootProject; foreach (var dependency in project.Dependencies) { if (!dependency.HasFlag(LibraryDependencyTypeFlag.BecomesNupkgDependency)) { continue; } // TODO: Efficiency var dependencyDescription = context.LibraryManager.GetLibraries().First(l => l.RequestedRanges.Contains(dependency)); // REVIEW: Can we get this far with unresolved dependencies if (dependencyDescription == null || !dependencyDescription.Resolved) { continue; } if (dependencyDescription.Identity.Type == LibraryType.Project && ((ProjectDescription)dependencyDescription).Project.EmbedInteropTypes) { continue; } if (dependency.Target == LibraryType.ReferenceAssembly) { packageBuilder.FrameworkAssemblies.Add(new FrameworkAssemblyReference(dependency.Name, new[] { context.TargetFramework })); Reporter.Verbose.WriteLine($"Adding framework assembly {dependency.Name.Yellow()}"); } else { VersionRange dependencyVersion = null; if (dependency.VersionRange == null || dependency.VersionRange.IsFloating) { dependencyVersion = new VersionRange(dependencyDescription.Identity.Version); } else { dependencyVersion = dependency.VersionRange; } Reporter.Verbose.WriteLine($"Adding dependency {dependency.Name.Yellow()} {VersionUtility.RenderVersion(dependencyVersion).Yellow()}"); dependencies.Add(new PackageDependency(dependency.Name, dependencyVersion)); } } packageBuilder.DependencySets.Add(new PackageDependencySet(context.TargetFramework, dependencies)); }
private IEnumerable<string> GetCommandArgs(ProjectContext projectContext, DotnetTestParams dotnetTestParams) { var commandArgs = new List<string> { new AssemblyUnderTest(projectContext, dotnetTestParams).Path }; commandArgs.AddRange(dotnetTestParams.RemainingArguments); return commandArgs; }
public static IEnumerable<string> GetCompilationSources(ProjectContext project, CommonCompilerOptions compilerOptions) { if (compilerOptions.CompileInclude == null) { return project.ProjectFile.Files.SourceFiles; } var includeFiles = IncludeFilesResolver.GetIncludeFiles(compilerOptions.CompileInclude, "/", diagnostics: null); return includeFiles.Select(f => f.SourcePath); }
private void CollectCheckPathProbingPreconditions(ProjectContext project, IncrementalPreconditions preconditions) { var pathCommands = CompilerUtil.GetCommandsInvokedByCompile(project) .Select(commandName => Command.CreateDotNet(commandName, Enumerable.Empty<string>(), project.TargetFramework)) .Where(c => c.ResolutionStrategy.Equals(CommandResolutionStrategy.Path)); foreach (var pathCommand in pathCommands) { preconditions.AddPathProbingPrecondition(project.ProjectName(), pathCommand.CommandName); } }
public static string GetDefaultRootOutputPath(ProjectContext context, string currentOutputPath) { var rootOutputPath = string.Empty; if (string.IsNullOrEmpty(currentOutputPath)) { rootOutputPath = context.ProjectFile.ProjectDirectory; } return rootOutputPath; }
private static PackageDescription GetCommandPackage(ProjectContext projectContext, string commandName) { return projectContext.LibraryManager.GetLibraries() .Where(l => l.GetType() == typeof (PackageDescription)) .Select(l => l as PackageDescription) .FirstOrDefault(p => p.Library.Files .Select(Path.GetFileName) .Where(f => Path.GetFileNameWithoutExtension(f) == commandName) .Select(Path.GetExtension) .Any(e => Env.ExecutableExtensions.Contains(e) || e == FileNameSuffixes.DotNet.DynamicLib)); }
private static CommandResult CompileProject(ProjectContext projectContext, string configuration, out string tempOutputDir) { tempOutputDir = Path.Combine(projectContext.ProjectDirectory, "bin", ".dotnetrepl", Guid.NewGuid().ToString("N")); Reporter.Output.WriteLine($"Compiling {projectContext.RootProject.Identity.Name.Yellow()} for {projectContext.TargetFramework.DotNetFrameworkName.Yellow()} to use with the {"C# REPL".Yellow()} environment."); // --temp-output is actually the intermediate output folder and can be the same as --output for our temporary compilation (`dotnet run` can be seen doing the same) return Command.Create($"dotnet-build", $"--output \"{tempOutputDir}\" --temp-output \"{tempOutputDir}\" --framework \"{projectContext.TargetFramework}\" --configuration \"{configuration}\" \"{projectContext.ProjectDirectory}\"") .ForwardStdOut(onlyIfVerbose: true) .ForwardStdErr() .Execute(); }