public static IGraphNode <LibraryDescription> Build([NotNull] IEnumerable <LibraryDescription> libraries, [NotNull] Runtime.Project project) { var root = libraries.FirstOrDefault(p => string.Equals(p.Identity.Name, project.Name)); if (root == null) { throw new InvalidOperationException(string.Format("Failed to retrieve {0} of project {1} - {2}", typeof(LibraryDependency).Name, project.Name, project.Version)); } // build a tree of LibraryDescriptions of the given project root return(DepthFirstGraphTraversal.PostOrderWalk <LibraryDescription, IGraphNode <LibraryDescription> >( node: root, getChildren: node => { if (node.Resolved) { return node.Dependencies.Select(dependency => dependency.Library); } else { return Enumerable.Empty <LibraryDescription>(); } }, visitNode: (node, children) => { return new GraphNode <LibraryDescription>(node, children); })); }
public Project(Runtime.Project runtimeProject) { ProjectFile = runtimeProject.ProjectFilePath; ProjectDirectory = runtimeProject.ProjectDirectory; Files = runtimeProject.Files.SourceFiles.Concat( runtimeProject.Files.ResourceFiles.Values.Concat( runtimeProject.Files.PreprocessSourceFiles.Concat( runtimeProject.Files.SharedFiles))).Concat( new string[] { runtimeProject.ProjectFilePath }) .ToList(); var projectLockJsonPath = Path.Combine(runtimeProject.ProjectDirectory, LockFileReader.LockFileName); var lockFileReader = new LockFileReader(); if (File.Exists(projectLockJsonPath)) { var lockFile = lockFileReader.Read(projectLockJsonPath); ProjectDependencies = lockFile.ProjectLibraries.Select(dep => GetProjectRelativeFullPath(dep.Path)).ToList(); } else { ProjectDependencies = new string[0]; } }
private void ApplyTargetFramework(XDocument xDoc, Runtime.Project project) { // Get the system.web element var systemWeb = GetOrAddElement(xDoc.Root, "system.web"); var httpRuntime = systemWeb.Element("httpRuntime"); // No httpRuntime element, so create it if (httpRuntime == null) { httpRuntime = new XElement("httpRuntime"); systemWeb.Add(httpRuntime); } // There is an httpRuntime element. The user may have already set this attribute... else if (httpRuntime.Attribute("targetFramework") != null) { // User already had a target framework, leave it alone return; } // Ok, now we have an httpRuntime element and we know we need to set thet targetFramework on it. var bestDnxVersion = project.GetTargetFrameworks() .Where(f => f.FrameworkName.Identifier.Equals(FrameworkNames.LongNames.Dnx)) .OrderByDescending(f => f.FrameworkName.Version) .Select(f => f.FrameworkName.Version) .FirstOrDefault(); if (bestDnxVersion != null) { httpRuntime.SetAttributeValue("targetFramework", bestDnxVersion.ToString()); } }
private Func <string, string> GetScriptVariable(Runtime.Project project, Func <string, string> getVariable) { var keys = new Dictionary <string, Func <string> >(StringComparer.OrdinalIgnoreCase) { { "project:Directory", () => project.ProjectDirectory }, { "project:Name", () => project.Name }, { "project:Version", () => project.Version.ToString() }, }; return(key => { // try returning key from dictionary Func <string> valueFactory; if (keys.TryGetValue(key, out valueFactory)) { return valueFactory(); } // try returning command-specific key var value = getVariable(key); if (!string.IsNullOrEmpty(value)) { return value; } // try returning environment variable return Environment.GetEnvironmentVariable(key); }); }
private DependencyContext CreateDependencyContext(Runtime.Project project, FrameworkName frameworkName) { var dependencyContext = new DependencyContext(project.ProjectDirectory, _options.Configuration, frameworkName); dependencyContext.Walk(project.Name, project.Version); return(dependencyContext); }
private static void InitializeBuilder(Runtime.Project project, PackageBuilder builder) { builder.Authors.AddRange(project.Authors); if (builder.Authors.Count == 0) { // TODO: K_AUTHOR is a temporary name var defaultAuthor = Environment.GetEnvironmentVariable("K_AUTHOR"); if (string.IsNullOrEmpty(defaultAuthor)) { builder.Authors.Add(project.Name); } else { builder.Authors.Add(defaultAuthor); } } builder.Description = project.Description ?? project.Name; builder.Id = project.Name; builder.Version = project.Version; builder.Title = project.Name; builder.RequireLicenseAcceptance = project.RequireLicenseAcceptance; builder.Tags.AddRange(project.Tags); if (!string.IsNullOrEmpty(project.ProjectUrl)) { builder.ProjectUrl = new Uri(project.ProjectUrl); } }
public InstallBuilder(Runtime.Project project, IPackageBuilder packageBuilder, Reports buildReport) { _project = project; _packageBuilder = packageBuilder; _buildReport = buildReport; IsApplicationPackage = project.Commands.Any(); }
public BuildContext(IServiceProvider hostServices, IApplicationEnvironment appEnv, CompilationEngineFactory compilationFactory, Runtime.Project project, FrameworkName targetFramework, string configuration, string outputPath) { _project = project; _targetFramework = targetFramework; _configuration = configuration; _targetFrameworkFolder = VersionUtility.GetShortFrameworkName(_targetFramework); _outputPath = Path.Combine(outputPath, _targetFrameworkFolder); _hostServices = hostServices; _appEnv = appEnv; _applicationHostContext = GetApplicationHostContext(project, targetFramework, configuration, compilationFactory.CompilationCache); var compilationEngine = compilationFactory.CreateEngine( new CompilationEngineContext( _applicationHostContext.LibraryManager, _applicationHostContext.ProjectGraphProvider, NoopWatcher.Instance, _applicationHostContext.ServiceProvider, _targetFramework, _configuration)); _libraryExporter = compilationEngine.CreateProjectExporter( _project, _targetFramework, _configuration); _applicationHostContext.AddService(typeof(ILibraryExporter), _libraryExporter); _applicationHostContext.AddService(typeof(ICompilationEngine), compilationEngine); }
public static IGraphNode <LibraryDescription> Build([NotNull] IList <LibraryDescription> libraries, [NotNull] Runtime.Project project) { var libDictionary = libraries.ToDictionary(desc => desc.Identity); LibraryDescription root; if (!libDictionary.TryGetValue(new Library { Name = project.Name, Version = project.Version }, out root)) { throw new InvalidOperationException(string.Format("Failed to retrieve {0} of project {1} - {2}", typeof(LibraryDependency).Name, project.Name, project.Version)); } // build a tree of LibraryDescriptions of the given project root return(DepthFirstGraphTraversal.PostOrderWalk <LibraryDescription, IGraphNode <LibraryDescription> >( node: root, getChildren: node => { if (node.Resolved) { return node.Dependencies.Select(dependency => libDictionary[dependency.Library]); } else { return Enumerable.Empty <LibraryDescription>(); } }, visitNode: (node, children) => { return new GraphNode <LibraryDescription>(node, children); })); }
public static LockFileTargetLibrary CreateLockFileTargetLibrary(LockFileProjectLibrary library, Runtime.Project projectInfo, RestoreContext context) { var lockFileLib = new LockFileTargetLibrary { Name = library.Name, Version = library.Version, Type = "project" }; var targetFrameworkInfo = projectInfo.GetTargetFramework(context.FrameworkName); var dependencies = projectInfo.Dependencies.Concat(targetFrameworkInfo.Dependencies); foreach (var dependency in dependencies) { if (dependency.LibraryRange.IsGacOrFrameworkReference) { lockFileLib.FrameworkAssemblies.Add( LibraryRange.GetAssemblyName(dependency.LibraryRange.Name)); } else { lockFileLib.Dependencies.Add(new PackageDependency( dependency.LibraryRange.Name, dependency.LibraryRange.VersionRange)); } } return(lockFileLib); }
private void CopyProject(PublishRoot root, Runtime.Project project, string targetPath, bool includeSource) { var additionalExcluding = new List <string>(); // If a public folder is specified with 'webroot' or '--wwwroot', we ignore it when copying project files var wwwRootPath = string.Empty; if (!string.IsNullOrEmpty(WwwRoot)) { wwwRootPath = Path.GetFullPath(Path.Combine(project.ProjectDirectory, WwwRoot)); wwwRootPath = PathUtility.EnsureTrailingSlash(wwwRootPath); } // If project root is used as value of '--wwwroot', we shouldn't exclude it when copying if (string.Equals(wwwRootPath, PathUtility.EnsureTrailingSlash(project.ProjectDirectory))) { wwwRootPath = string.Empty; } if (!string.IsNullOrEmpty(wwwRootPath)) { additionalExcluding.Add(wwwRootPath.Substring(PathUtility.EnsureTrailingSlash(project.ProjectDirectory).Length)); } var sourceFiles = project.Files.GetFilesForBundling(includeSource, additionalExcluding); root.Operations.Copy(sourceFiles, project.ProjectDirectory, targetPath); }
public static IEnumerable <FrameworkName> SelectFrameworks(Runtime.Project project, IDictionary <FrameworkName, string> specifiedFrameworks, FrameworkName fallbackFramework, out string errorMessage) { var projectFrameworks = new HashSet <FrameworkName>( project.GetTargetFrameworks() .Select(c => c.FrameworkName)); IEnumerable <FrameworkName> frameworks = null; if (projectFrameworks.Count > 0) { // Specified target frameworks have to be a subset of the project frameworks if (!ValidateFrameworks(projectFrameworks, specifiedFrameworks, out errorMessage)) { return(null); } frameworks = specifiedFrameworks.Count > 0 ? specifiedFrameworks.Keys : (IEnumerable <FrameworkName>)projectFrameworks; } else { frameworks = new[] { fallbackFramework }; } errorMessage = string.Empty; return(frameworks); }
public PackRoot(Runtime.Project project, string outputPath, IServiceProvider hostServices) { _project = project; Projects = new List <PackProject>(); Packages = new List <PackPackage>(); Runtimes = new List <PackRuntime>(); OutputPath = outputPath; HostServices = hostServices; PackagesPath = Path.Combine(outputPath, AppRootName, "packages"); Operations = new PackOperations(); }
public static Runtime.Project FindProject(this IProjectResolver resolver, string name) { Runtime.Project project = null; if (resolver.TryResolveProject(name, out project)) { return(project); } else { return(null); } }
private void CopyContentFiles(PackRoot root, Runtime.Project project, string targetFolderPath) { root.Reports.Quiet.WriteLine("Copying contents of {0} dependency {1} to {2}", _libraryDescription.Type, _libraryDescription.Identity.Name, targetFolderPath); var contentSourcePath = GetWwwRootSourcePath(project.ProjectDirectory, WwwRoot); root.Reports.Quiet.WriteLine(" Source {0}", contentSourcePath); root.Reports.Quiet.WriteLine(" Target {0}", targetFolderPath); root.Operations.Copy(contentSourcePath, targetFolderPath); }
private void CopyProject(PackRoot root, Runtime.Project project, string targetPath, bool includeSource) { // A set of excluded files/directories used as a filter when doing copy var excludeSet = new HashSet <string>(project.PackExcludeFiles, StringComparer.OrdinalIgnoreCase); var contentFiles = new HashSet <string>(project.ContentFiles, StringComparer.OrdinalIgnoreCase); // If a public folder is specified with 'webroot' or '--wwwroot', we ignore it when copying project files var wwwRootPath = string.Empty; if (!string.IsNullOrEmpty(WwwRoot)) { wwwRootPath = Path.Combine(project.ProjectDirectory, WwwRoot); wwwRootPath = PathUtility.EnsureTrailingSlash(wwwRootPath); } // If project root is used as value of '--wwwroot', we shouldn't exclude it when copying if (string.Equals(wwwRootPath, PathUtility.EnsureTrailingSlash(project.ProjectDirectory))) { wwwRootPath = string.Empty; } root.Operations.Copy(project.ProjectDirectory, targetPath, itemPath => { // If current file/folder is in the exclusion list, we don't copy it if (excludeSet.Contains(itemPath)) { return(false); } // If current file is in the public folder, we don't copy it to destination project if (!string.IsNullOrEmpty(wwwRootPath) && itemPath.StartsWith(wwwRootPath)) { return(false); } // The full path of target generated by copy operation should also be excluded var targetFullPath = itemPath.Replace(project.ProjectDirectory, TargetPath); excludeSet.Add(targetFullPath); if (includeSource) { return(true); } if (Directory.Exists(itemPath)) { return(true); } return(contentFiles.Contains(itemPath)); }); }
private IAssemblyLoadContextFactory GetRuntimeLoadContextFactory(Runtime.Project project) { var applicationHostContext = new ApplicationHostContext(_hostServices, project.ProjectDirectory, packagesDirectory: null, configuration: _appEnv.Configuration, targetFramework: _appEnv.RuntimeFramework, loadContextFactory: null); applicationHostContext.DependencyWalker.Walk(project.Name, project.Version, _appEnv.RuntimeFramework); return(new AssemblyLoadContextFactory(applicationHostContext.ServiceProvider)); }
public static LockFileProjectLibrary CreateLockFileProjectLibrary(Runtime.Project project, Runtime.Project projectDependency) { var result = new LockFileProjectLibrary() { Name = projectDependency.Name, Version = projectDependency.Version }; result.Path = PathUtility.GetRelativePath(project.ProjectFilePath, projectDependency.ProjectFilePath, '/'); return(result); }
public PublishRoot(Runtime.Project project, string outputPath, IServiceProvider hostServices, Reports reports) { _project = project; Reports = reports; Projects = new List <PublishProject>(); Packages = new List <PublishPackage>(); Runtimes = new List <PublishRuntime>(); OutputPath = outputPath; HostServices = hostServices; TargetPackagesPath = Path.Combine(outputPath, AppRootName, "packages"); TargetRuntimesPath = Path.Combine(outputPath, AppRootName, "runtimes"); Operations = new PublishOperations(); }
public BundleRoot(Runtime.Project project, string outputPath, IServiceProvider hostServices, Reports reports) { _project = project; Reports = reports; Projects = new List <BundleProject>(); Packages = new List <BundlePackage>(); Runtimes = new List <BundleRuntime>(); OutputPath = outputPath; HostServices = hostServices; TargetPackagesPath = Path.Combine(outputPath, AppRootName, "packages"); Operations = new BundleOperations(); LibraryDependencyContexts = new Dictionary <Library, IList <DependencyContext> >(); }
public PublishRoot(Runtime.Project project, string outputPath, IServiceProvider hostServices, Reports reports) { _project = project; Reports = reports; Projects = new List<PublishProject>(); Packages = new List<PublishPackage>(); Runtimes = new List<PublishRuntime>(); OutputPath = outputPath; HostServices = hostServices; TargetPackagesPath = Path.Combine(outputPath, AppRootName, "packages"); Operations = new PublishOperations(); LibraryDependencyContexts = new Dictionary<Library, IList<DependencyContext>>(); }
public static TargetFrameworkInformation GetCompatibleTargetFramework(this Runtime.Project project, FrameworkName targetFramework) { IEnumerable<TargetFrameworkInformation> targets; if (VersionUtility.GetNearest(targetFramework, project.GetTargetFrameworks(), out targets) && targets.Any()) { return targets.FirstOrDefault(); } return new TargetFrameworkInformation { Dependencies = new List<LibraryDependency>() }; }
public PublishRoot(Runtime.Project project, string outputPath, IServiceProvider hostServices, Reports reports) { _project = project; Reports = reports; Projects = new List<PublishProject>(); Packages = new List<PublishPackage>(); Runtimes = new List<PublishRuntime>(); Frameworks = new Dictionary<FrameworkName, string>(); OutputPath = outputPath; HostServices = hostServices; TargetPackagesPath = Path.Combine(outputPath, AppRootName, "packages"); TargetRuntimesPath = Path.Combine(outputPath, AppRootName, "runtimes"); Operations = new PublishOperations(); }
public DependencyContext(Runtime.Project project, FrameworkName targetFramework) { var applicationHostContext = new ApplicationHostContext { Project = project, TargetFramework = targetFramework }; ApplicationHostContext.Initialize(applicationHostContext); FrameworkName = targetFramework; LibraryManager = applicationHostContext.LibraryManager; PackagesDirectory = applicationHostContext.PackagesDirectory; }
private void WriteLockFile(string projectLockFilePath, Runtime.Project project, List <GraphItem> graphItems, PackageRepository repository, IEnumerable <FrameworkName> frameworks) { var lockFile = new LockFile(); lockFile.Islocked = Lock; using (var sha512 = SHA512.Create()) { foreach (var item in graphItems.OrderBy(x => x.Match.Library, new LibraryComparer())) { var library = item.Match.Library; var packageInfo = repository.FindPackagesById(library.Name) .FirstOrDefault(p => p.Version == library.Version); if (packageInfo == null) { continue; } var package = packageInfo.Package; var lockFileLib = LockFileUtils.CreateLockFileLibraryForProject( project, package, sha512, frameworks, new DefaultPackagePathResolver(repository.RepositoryRoot), correctedPackageName: library.Name); lockFile.Libraries.Add(lockFileLib); } } // Use empty string as the key of dependencies shared by all frameworks lockFile.ProjectFileDependencyGroups.Add(new ProjectFileDependencyGroup( string.Empty, project.Dependencies.Select(x => x.LibraryRange.ToString()))); foreach (var frameworkInfo in project.GetTargetFrameworks()) { lockFile.ProjectFileDependencyGroups.Add(new ProjectFileDependencyGroup( frameworkInfo.FrameworkName.ToString(), frameworkInfo.Dependencies.Select(x => x.LibraryRange.ToString()))); } var lockFileFormat = new LockFileFormat(); lockFileFormat.Write(projectLockFilePath, lockFile); }
public PublishRoot(Runtime.Project project, string outputPath, Reports reports) { _project = project; MainProjectName = project.Name; Reports = reports; Projects = new List <PublishProject>(); Packages = new List <PublishPackage>(); Runtimes = new List <PublishRuntime>(); RuntimeIdentifiers = new HashSet <string>(); Frameworks = new Dictionary <FrameworkName, string>(); OutputPath = outputPath; TargetPackagesPath = Path.Combine(outputPath, AppRootName, "packages"); TargetRuntimesPath = Path.Combine(outputPath, AppRootName, "runtimes"); Operations = new PublishOperations(); }
public PublishRoot(Runtime.Project project, string outputPath, Reports reports) { _project = project; MainProjectName = project.Name; Reports = reports; Projects = new List<PublishProject>(); Packages = new List<PublishPackage>(); Runtimes = new List<PublishRuntime>(); RuntimeIdentifiers = new HashSet<string>(); Frameworks = new Dictionary<FrameworkName, string>(); OutputPath = outputPath; TargetPackagesPath = Path.Combine(outputPath, AppRootName, "packages"); TargetRuntimesPath = Path.Combine(outputPath, AppRootName, "runtimes"); Operations = new PublishOperations(); }
public DependencyContext(Runtime.Project project, FrameworkName targetFramework, IEnumerable <string> runtimeIdentifiers) { var applicationHostContext = new ApplicationHostContext { Project = project, TargetFramework = targetFramework, RuntimeIdentifiers = runtimeIdentifiers }; ApplicationHostContext.Initialize(applicationHostContext); FrameworkName = targetFramework; LibraryManager = applicationHostContext.LibraryManager; PackagesDirectory = applicationHostContext.PackagesDirectory; RuntimeIdentifiers = runtimeIdentifiers; }
public BuildContext(ICache cache, ICacheContextAccessor cacheContextAccessor, Runtime.Project project, FrameworkName targetFramework, string configuration, string outputPath) { _project = project; _targetFramework = targetFramework; _configuration = configuration; _targetFrameworkFolder = VersionUtility.GetShortFrameworkName(_targetFramework); _outputPath = Path.Combine(outputPath, _targetFrameworkFolder); _applicationHostContext = new ApplicationHostContext( serviceProvider: null, projectDirectory: project.ProjectDirectory, packagesDirectory: null, configuration: configuration, targetFramework: targetFramework, cache: cache, cacheContextAccessor: cacheContextAccessor, namedCacheDependencyProvider: new NamedCacheDependencyProvider()); }
public BuildContext(CompilationEngine compilationEngine, Runtime.Project project, FrameworkName targetFramework, string configuration, string outputPath) { _project = project; _targetFramework = targetFramework; _configuration = configuration; _targetFrameworkFolder = VersionUtility.GetShortFrameworkName(_targetFramework); _outputPath = Path.Combine(outputPath, _targetFrameworkFolder); _libraryExporter = compilationEngine.CreateProjectExporter( _project, _targetFramework, _configuration); _libraryManager = _libraryExporter.LibraryManager; }
private void CopyContentFiles(PackRoot root, Runtime.Project project, string targetFolderPath) { root.Reports.Quiet.WriteLine("Copying contents of {0} dependency {1} to {2}", _libraryDescription.Type, _libraryDescription.Identity.Name, targetFolderPath); var contentSourceFolder = WwwRoot ?? string.Empty; var contentSourcePath = Path.Combine(project.ProjectDirectory, contentSourceFolder); // If the value of '--wwwroot' is ".", we need to pack the project root dir // Use Path.GetFullPath() to get rid of the trailing "." contentSourcePath = Path.GetFullPath(contentSourcePath); root.Reports.Quiet.WriteLine(" Source {0}", contentSourcePath); root.Reports.Quiet.WriteLine(" Target {0}", targetFolderPath); root.Operations.Copy(contentSourcePath, targetFolderPath); }
private ApplicationHostContext GetApplicationHostContext(Runtime.Project project, FrameworkName targetFramework, string configuration, CompilationCache cache) { var cacheKey = Tuple.Create("ApplicationContext", project.Name, configuration, targetFramework); return(cache.Cache.Get <ApplicationHostContext>(cacheKey, ctx => { var applicationHostContext = new ApplicationHostContext(hostServices: _hostServices, projectDirectory: project.ProjectDirectory, packagesDirectory: null, configuration: configuration, targetFramework: targetFramework, loadContextFactory: GetRuntimeLoadContextFactory(project)); applicationHostContext.DependencyWalker.Walk(project.Name, project.Version, targetFramework); return applicationHostContext; })); }
public static IGraphNode<LibraryDependency> Build( IEnumerable<LibraryDescription> libraries, Runtime.Project project) { if (libraries == null) { throw new ArgumentNullException(nameof(libraries)); } if (project == null) { throw new ArgumentNullException(nameof(project)); } var root = new LibraryDependency { Library = libraries.FirstOrDefault(p => string.Equals(p.Identity.Name, project.Name)), LibraryRange = null }; if (root.Library == null) { throw new InvalidOperationException($"Failed to retrieve {nameof(LibraryDependency)} of project {project.Name}/{project.Version}"); } // build a tree of LibraryDescriptions of the given project root return DepthFirstGraphTraversal.PostOrderWalk<LibraryDependency, IGraphNode<LibraryDependency>>( node: root, getChildren: node => { if (node.Library.Resolved) { return node.Library.Dependencies; } else { return Enumerable.Empty<LibraryDependency>(); } }, visitNode: (node, children) => { return new GraphNode<LibraryDependency>(node, children); }); }
public SourceBuilder(Runtime.Project project, IPackageBuilder packageBuilder, Reports buildReport) { if (project == null) { throw new ArgumentNullException(nameof(project)); } if (buildReport == null) { throw new ArgumentNullException(nameof(buildReport)); } if (packageBuilder == null) { throw new ArgumentNullException(nameof(packageBuilder)); } _project = project; _packageBuilder = packageBuilder; _reports = buildReport; }
public BuildContext(IServiceProvider hostServices, IApplicationEnvironment appEnv, ICache cache, ICacheContextAccessor cacheContextAccessor, Runtime.Project project, FrameworkName targetFramework, string configuration, string outputPath) { _project = project; _targetFramework = targetFramework; _configuration = configuration; _targetFrameworkFolder = VersionUtility.GetShortFrameworkName(_targetFramework); _outputPath = Path.Combine(outputPath, _targetFrameworkFolder); _hostServices = hostServices; _cache = cache; _cacheContextAccessor = cacheContextAccessor; _appEnv = appEnv; _applicationHostContext = GetApplicationHostContext(project, targetFramework, configuration); }