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); }
internal ProjectContext( GlobalSettings globalSettings, ProjectDescription rootProject, NuGetFramework targetFramework, string runtimeIdentifier, string packagesDirectory, LibraryManager libraryManager) { GlobalSettings = globalSettings; RootProject = rootProject; TargetFramework = targetFramework; RuntimeIdentifier = runtimeIdentifier; PackagesDirectory = packagesDirectory; LibraryManager = libraryManager; }
internal ProjectContext( GlobalSettings globalSettings, ProjectDescription rootProject, LibraryDescription platformLibrary, NuGetFramework targetFramework, bool isPortable, string runtimeIdentifier, string packagesDirectory, LibraryManager libraryManager, LockFile lockfile, List<DiagnosticMessage> diagnostics) { Identity = new ProjectContextIdentity(rootProject?.Path, targetFramework); GlobalSettings = globalSettings; RootProject = rootProject; PlatformLibrary = platformLibrary; TargetFramework = targetFramework; RuntimeIdentifier = runtimeIdentifier; PackagesDirectory = packagesDirectory; LibraryManager = libraryManager; LockFile = lockfile; IsPortable = isPortable; Diagnostics = diagnostics; }
private static void Sort(ProjectDescription project, Dictionary<string, ProjectDescription> projects, ISet<ProjectDescription> outputs) { // Sorts projects in dependency order so that we only build them once per chain foreach (var dependency in project.Dependencies) { ProjectDescription projectDependency; if (projects.TryGetValue(dependency.Name, out projectDependency)) { Sort(projectDependency, projects, outputs); } } outputs.Add(project); }
private bool InvokeCompileOnDependency(ProjectDescription projectDependency) { var args = new List<string>(); args.Add("--framework"); args.Add($"{projectDependency.Framework}"); args.Add("--configuration"); args.Add(_args.ConfigValue); args.Add(projectDependency.Project.ProjectDirectory); var compileResult = Command.CreateDotNet("compile", args) .ForwardStdOut() .ForwardStdErr() .Execute(); return compileResult.ExitCode == 0; }
private bool DependencyNeedsRebuilding(ProjectDescription dependency) { var dependencyProjectContext = ProjectContext.Create(dependency.Path, dependency.Framework, new[] { _rootProject.RuntimeIdentifier }); return NeedsRebuilding(dependencyProjectContext, new ProjectDependenciesFacade(dependencyProjectContext, _args.ConfigValue)); }
private bool InvokeCompileOnDependency(ProjectDescription projectDependency) { var args = new List<string>(); args.Add("--framework"); args.Add($"{projectDependency.Framework}"); args.Add("--configuration"); args.Add(_args.ConfigValue); args.Add(projectDependency.Project.ProjectDirectory); if (!string.IsNullOrWhiteSpace(_args.RuntimeValue)) { args.Add("--runtime"); args.Add(_args.RuntimeValue); } if (!string.IsNullOrEmpty(_args.VersionSuffixValue)) { args.Add("--version-suffix"); args.Add(_args.VersionSuffixValue); } if (!string.IsNullOrWhiteSpace(_args.BuildBasePathValue)) { args.Add("--build-base-path"); args.Add(_args.BuildBasePathValue); } var compileResult = CommpileCommand.Run(args.ToArray()); return compileResult == 0; }
private bool InvokeCompileOnDependency(ProjectDescription projectDependency, string outputPath, string intermediateOutputPath) { var compileResult = Command.Create("dotnet-compile", $"--framework {projectDependency.Framework} " + $"--configuration {_args.ConfigValue} " + $"--output \"{outputPath}\" " + $"--temp-output \"{intermediateOutputPath}\" " + (_args.NoHostValue ? "--no-host " : string.Empty) + $"\"{projectDependency.Project.ProjectDirectory}\"") .ForwardStdOut() .ForwardStdErr() .Execute(); return compileResult.ExitCode == 0; }
public ProjectContext Build() { var diagnostics = new List <DiagnosticMessage>(); ProjectDirectory = Project?.ProjectDirectory ?? ProjectDirectory; GlobalSettings globalSettings = null; if (ProjectDirectory != null) { RootDirectory = ProjectRootResolver.ResolveRootDirectory(ProjectDirectory); GlobalSettings.TryGetGlobalSettings(RootDirectory, out globalSettings); } RootDirectory = globalSettings?.DirectoryPath ?? RootDirectory; FrameworkReferenceResolver frameworkReferenceResolver; if (string.IsNullOrEmpty(ReferenceAssembliesPath)) { // Use the default static resolver frameworkReferenceResolver = FrameworkReferenceResolver.Default; } else { frameworkReferenceResolver = new FrameworkReferenceResolver(ReferenceAssembliesPath); } LockFileLookup lockFileLookup = null; EnsureProjectLoaded(); ReadLockFile(diagnostics); // some callers only give ProjectContextBuilder a LockFile ProjectDirectory = ProjectDirectory ?? TryGetProjectDirectoryFromLockFile(); INuGetPathContext nugetPathContext = null; if (ProjectDirectory != null) { nugetPathContext = NuGetPathContext.Create(ProjectDirectory); } PackagesDirectory = PackagesDirectory ?? nugetPathContext?.UserPackageFolder; var validLockFile = true; string lockFileValidationMessage = null; if (LockFile != null) { if (Project != null) { validLockFile = LockFile.IsValidForProject(Project, out lockFileValidationMessage); } lockFileLookup = new LockFileLookup(LockFile); } var libraries = new Dictionary <LibraryKey, LibraryDescription>(); var projectResolver = new ProjectDependencyProvider(ProjectResolver); ProjectDescription mainProject = null; if (Project != null) { mainProject = projectResolver.GetDescription(TargetFramework, Project, targetLibrary: null); // Add the main project libraries.Add(new LibraryKey(mainProject.Identity.Name), mainProject); } ProjectLibraryDependency platformDependency = null; if (mainProject != null) { platformDependency = mainProject.Dependencies .Where(d => d.Type.Equals(LibraryDependencyType.Platform)) .Cast <ProjectLibraryDependency>() .FirstOrDefault(); } bool isPortable = platformDependency != null; LockFileTarget target = null; LibraryDescription platformLibrary = null; if (lockFileLookup != null) { target = SelectTarget(LockFile, isPortable); if (target != null) { var nugetPackageResolver = new PackageDependencyProvider(nugetPathContext, frameworkReferenceResolver); var msbuildProjectResolver = new MSBuildDependencyProvider(Project, ProjectResolver); ScanLibraries(target, lockFileLookup, libraries, msbuildProjectResolver, nugetPackageResolver, projectResolver); if (platformDependency != null) { libraries.TryGetValue(new LibraryKey(platformDependency.Name), out platformLibrary); } } } string runtime = target?.RuntimeIdentifier; if (string.IsNullOrEmpty(runtime) && TargetFramework.IsDesktop()) { // we got a ridless target for desktop so turning portable mode on isPortable = true; var legacyRuntime = RuntimeEnvironmentRidExtensions.GetLegacyRestoreRuntimeIdentifier(); if (RuntimeIdentifiers.Contains(legacyRuntime)) { runtime = legacyRuntime; } else { runtime = RuntimeIdentifiers.FirstOrDefault(); } } var referenceAssemblyDependencyResolver = new ReferenceAssemblyDependencyResolver(frameworkReferenceResolver); bool requiresFrameworkAssemblies; // Resolve the dependencies ResolveDependencies(libraries, referenceAssemblyDependencyResolver, out requiresFrameworkAssemblies); // REVIEW: Should this be in NuGet (possibly stored in the lock file?) if (LockFile == null) { diagnostics.Add(new DiagnosticMessage( ErrorCodes.NU1009, $"The expected lock file doesn't exist. Please run \"dotnet restore\" to generate a new lock file.", Path.Combine(Project.ProjectDirectory, LockFileFormat.LockFileName), DiagnosticMessageSeverity.Error)); } if (!validLockFile) { diagnostics.Add(new DiagnosticMessage( ErrorCodes.NU1006, $"{lockFileValidationMessage}. Please run \"dotnet restore\" to generate a new lock file.", Path.Combine(Project.ProjectDirectory, LockFileFormat.LockFileName), DiagnosticMessageSeverity.Warning)); } if (requiresFrameworkAssemblies) { var frameworkInfo = Project.GetTargetFramework(TargetFramework); if (frameworkReferenceResolver == null || string.IsNullOrEmpty(frameworkReferenceResolver.ReferenceAssembliesPath)) { // If there was an attempt to use reference assemblies but they were not installed // report an error diagnostics.Add(new DiagnosticMessage( ErrorCodes.DOTNET1012, $"The reference assemblies directory was not specified. You can set the location using the DOTNET_REFERENCE_ASSEMBLIES_PATH environment variable.", filePath: Project.ProjectFilePath, severity: DiagnosticMessageSeverity.Error, startLine: frameworkInfo.Line, startColumn: frameworkInfo.Column )); } else if (!frameworkReferenceResolver.IsInstalled(TargetFramework)) { // If there was an attempt to use reference assemblies but they were not installed // report an error diagnostics.Add(new DiagnosticMessage( ErrorCodes.DOTNET1011, $"Framework not installed: {TargetFramework.DotNetFrameworkName} in {ReferenceAssembliesPath}", filePath: Project.ProjectFilePath, severity: DiagnosticMessageSeverity.Error, startLine: frameworkInfo.Line, startColumn: frameworkInfo.Column )); } } List <DiagnosticMessage> allDiagnostics = new List <DiagnosticMessage>(diagnostics); if (Project != null) { allDiagnostics.AddRange(Project.Diagnostics); } // Create a library manager var libraryManager = new LibraryManager(libraries.Values.ToList(), allDiagnostics, Project?.ProjectFilePath); return(new ProjectContext( globalSettings, mainProject, platformLibrary, TargetFramework, isPortable, runtime, PackagesDirectory, libraryManager, LockFile, diagnostics)); }
public ProjectContext Build() { var diagnostics = new List <DiagnosticMessage>(); ProjectDirectory = Project?.ProjectDirectory ?? ProjectDirectory; if (GlobalSettings == null && ProjectDirectory != null) { RootDirectory = ProjectRootResolver.ResolveRootDirectory(ProjectDirectory); GlobalSettings globalSettings; if (GlobalSettings.TryGetGlobalSettings(RootDirectory, out globalSettings)) { GlobalSettings = globalSettings; } } RootDirectory = GlobalSettings?.DirectoryPath ?? RootDirectory; PackagesDirectory = PackagesDirectory ?? PackageDependencyProvider.ResolvePackagesPath(RootDirectory, GlobalSettings); ReferenceAssembliesPath = ReferenceAssembliesPath ?? FrameworkReferenceResolver.GetDefaultReferenceAssembliesPath(); var frameworkReferenceResolver = new FrameworkReferenceResolver(ReferenceAssembliesPath); LockFileLookup lockFileLookup = null; EnsureProjectLoaded(); ReadLockFile(diagnostics); var validLockFile = true; string lockFileValidationMessage = null; if (LockFile != null) { if (Project != null) { validLockFile = LockFile.IsValidForProject(Project, out lockFileValidationMessage); } lockFileLookup = new LockFileLookup(LockFile); } var libraries = new Dictionary <LibraryKey, LibraryDescription>(); var projectResolver = new ProjectDependencyProvider(ProjectResolver); ProjectDescription mainProject = null; if (Project != null) { mainProject = projectResolver.GetDescription(TargetFramework, Project, targetLibrary: null); // Add the main project libraries.Add(new LibraryKey(mainProject.Identity.Name), mainProject); } LockFileTarget target = null; if (lockFileLookup != null) { target = SelectTarget(LockFile); if (target != null) { var nugetPackageResolver = new PackageDependencyProvider(PackagesDirectory, frameworkReferenceResolver); var msbuildProjectResolver = new MSBuildDependencyProvider(Project, ProjectResolver); ScanLibraries(target, lockFileLookup, libraries, msbuildProjectResolver, nugetPackageResolver, projectResolver); } } var referenceAssemblyDependencyResolver = new ReferenceAssemblyDependencyResolver(frameworkReferenceResolver); bool requiresFrameworkAssemblies; // Resolve the dependencies ResolveDependencies(libraries, referenceAssemblyDependencyResolver, out requiresFrameworkAssemblies); // REVIEW: Should this be in NuGet (possibly stored in the lock file?) if (LockFile == null) { diagnostics.Add(new DiagnosticMessage( ErrorCodes.NU1009, $"The expected lock file doesn't exist. Please run \"dotnet restore\" to generate a new lock file.", Path.Combine(Project.ProjectDirectory, LockFile.FileName), DiagnosticMessageSeverity.Error)); } if (!validLockFile) { diagnostics.Add(new DiagnosticMessage( ErrorCodes.NU1006, $"{lockFileValidationMessage}. Please run \"dotnet restore\" to generate a new lock file.", Path.Combine(Project.ProjectDirectory, LockFile.FileName), DiagnosticMessageSeverity.Warning)); } if (requiresFrameworkAssemblies) { var frameworkInfo = Project.GetTargetFramework(TargetFramework); if (string.IsNullOrEmpty(ReferenceAssembliesPath)) { // If there was an attempt to use reference assemblies but they were not installed // report an error diagnostics.Add(new DiagnosticMessage( ErrorCodes.DOTNET1012, $"The reference assemblies directory was not specified. You can set the location using the DOTNET_REFERENCE_ASSEMBLIES_PATH environment variable.", filePath: Project.ProjectFilePath, severity: DiagnosticMessageSeverity.Error, startLine: frameworkInfo.Line, startColumn: frameworkInfo.Column )); } else if (!frameworkReferenceResolver.IsInstalled(TargetFramework)) { // If there was an attempt to use reference assemblies but they were not installed // report an error diagnostics.Add(new DiagnosticMessage( ErrorCodes.DOTNET1011, $"Framework not installed: {TargetFramework.DotNetFrameworkName} in {ReferenceAssembliesPath}", filePath: Project.ProjectFilePath, severity: DiagnosticMessageSeverity.Error, startLine: frameworkInfo.Line, startColumn: frameworkInfo.Column )); } } // Create a library manager var libraryManager = new LibraryManager(libraries.Values.ToList(), diagnostics, Project?.ProjectFilePath); return(new ProjectContext( GlobalSettings, mainProject, TargetFramework, target?.RuntimeIdentifier, PackagesDirectory, libraryManager, LockFile)); }
private bool InvokeCompileOnDependency(ProjectDescription projectDependency) { var args = new List<string>(); args.Add("--framework"); args.Add($"{projectDependency.Framework}"); args.Add("--configuration"); args.Add($"{_args.ConfigValue}"); args.Add("--output"); args.Add($"{_args.OutputValue}"); args.Add("--temp-output"); args.Add($"{_args.IntermediateValue}"); args.Add($"{projectDependency.Project.ProjectDirectory}"); if (_args.NoHostValue) { args.Add("--no-host"); } var compileResult = Command.Create("dotnet-compile", args) .ForwardStdOut() .ForwardStdErr() .Execute(); return compileResult.ExitCode == 0; }