public async Task Emit(PublishRoot root) { root.Reports.Quiet.WriteLine("Using {0} dependency {1}", _libraryDescription.Type, Library); var packagePathResolver = new DefaultPackagePathResolver(root.SourcePackagesPath); var srcNupkgPath = packagePathResolver.GetPackageFilePath(_libraryDescription.Identity.Name, _libraryDescription.Identity.Version); var options = new Packages.AddOptions { NuGetPackage = srcNupkgPath, PackageHashFilePath = Path.ChangeExtension(srcNupkgPath, NuGet.Constants.HashFileExtension), SourcePackages = root.TargetPackagesPath, }; // Mute "packages add" subcommand options.Reports = Reports.Constants.NullReports; var packagesAddCommand = new Packages.AddCommand(options); await packagesAddCommand.Execute(); }
private bool EmitNupkg(PublishRoot root) { root.Reports.Quiet.WriteLine(" Packing nupkg from {0} dependency {1}", _projectDescription.Type, _projectDescription.Identity.Name); IsPackage = true; var project = GetCurrentProject(); var resolver = new DefaultPackagePathResolver(root.TargetPackagesPath); var targetNupkg = resolver.GetPackageFileName(project.Name, project.Version); TargetPath = resolver.GetInstallPath(project.Name, project.Version); root.Reports.Quiet.WriteLine(" Source {0}", _projectDescription.Path.Bold()); root.Reports.Quiet.WriteLine(" Target {0}", TargetPath); if (Directory.Exists(TargetPath)) { root.Operations.Delete(TargetPath); } // If this is a wrapper project, we need to generate a lock file before building it if (IsWrappingAssembly()) { var success = Restore(root, publishProject: this, restoreDirectory: project.ProjectDirectory) .GetAwaiter().GetResult(); if (!success) { return(false); } } // Generate nupkg from this project dependency var buildOptions = new BuildOptions(); buildOptions.ProjectPatterns.Add(project.ProjectDirectory); buildOptions.OutputDir = Path.Combine(project.ProjectDirectory, "bin"); buildOptions.Configurations.Add(root.Configuration); buildOptions.GeneratePackages = true; buildOptions.Reports = root.Reports.ShallowCopy(); // Mute "dnu pack" completely if it is invoked by "dnu publish --quiet" buildOptions.Reports.Information = root.Reports.Quiet; var buildManager = new BuildManager(root.HostServices, buildOptions); if (!buildManager.Build()) { return(false); } // Extract the generated nupkg to target path var srcNupkgPath = Path.Combine(buildOptions.OutputDir, root.Configuration, targetNupkg); var srcSymbolsNupkgPath = Path.ChangeExtension(srcNupkgPath, "symbols.nupkg"); var options = new Packages.AddOptions { NuGetPackage = root.IncludeSymbols ? srcSymbolsNupkgPath : srcNupkgPath, SourcePackages = root.TargetPackagesPath, Reports = root.Reports }; var packagesAddCommand = new Packages.AddCommand(options); packagesAddCommand.Execute().GetAwaiter().GetResult(); // Copy content files (e.g. html, js and images) of main project into "root" folder of the exported package var rootFolderPath = Path.Combine(TargetPath, "root"); var rootProjectJson = Path.Combine(rootFolderPath, Runtime.Project.ProjectFileName); root.Operations.Delete(rootFolderPath); CopyProject(root, project, rootFolderPath, includeSource: false); UpdateWebRoot(root, rootFolderPath); UpdateJson(rootProjectJson, jsonObj => { // Update the project entrypoint jsonObj["entryPoint"] = _projectDescription.Identity.Name; // Set mark this as non loadable jsonObj["loadable"] = false; // Update the dependencies node to reference the main project var deps = new JObject(); jsonObj["dependencies"] = deps; deps[_projectDescription.Identity.Name] = _projectDescription.Identity.Version.ToString(); }); var appBase = Path.Combine(PublishRoot.AppRootName, "packages", resolver.GetPackageDirectory(_projectDescription.Identity.Name, _projectDescription.Identity.Version), "root"); _relativeAppBase = Path.Combine("..", appBase); ApplicationBasePath = Path.Combine(root.OutputPath, appBase); root.Reports.Quiet.WriteLine("Removing {0}", srcNupkgPath); File.Delete(srcNupkgPath); root.Reports.Quiet.WriteLine("Removing {0}", srcSymbolsNupkgPath); File.Delete(srcSymbolsNupkgPath); return(true); }
private bool EmitNupkg(PublishRoot root) { root.Reports.Quiet.WriteLine(" Packing nupkg from {0} dependency {1}", _projectDescription.Type, _projectDescription.Identity.Name); IsPackage = true; var project = GetCurrentProject(); if (project == null) { return false; } var resolver = new DefaultPackagePathResolver(root.TargetPackagesPath); var targetNupkg = resolver.GetPackageFileName(project.Name, project.Version); TargetPath = resolver.GetInstallPath(project.Name, project.Version); root.Reports.Quiet.WriteLine(" Source {0}", _projectDescription.Path.Bold()); root.Reports.Quiet.WriteLine(" Target {0}", TargetPath); if (Directory.Exists(TargetPath)) { root.Operations.Delete(TargetPath); } // If this is a wrapper project, we need to generate a lock file before building it if (IsWrappingAssembly()) { var success = Restore(root, publishProject: this, restoreDirectory: project.ProjectDirectory) .GetAwaiter().GetResult(); if (!success) { return false; } } // Generate nupkg from this project dependency var buildOptions = new BuildOptions(); buildOptions.ProjectPatterns.Add(project.ProjectDirectory); buildOptions.OutputDir = Path.Combine(project.ProjectDirectory, "bin"); buildOptions.Configurations.Add(root.Configuration); buildOptions.GeneratePackages = true; buildOptions.Reports = root.Reports.ShallowCopy(); if (root.Frameworks.Any()) { // Make sure we only emit the nupkgs for the specified frameworks // We need to pick actual project frameworks relevant to the publish // but the project may not target exactly the right framework so we need // to use a compatibility check. foreach (var framework in root.Frameworks) { var selectedFramework = project.GetCompatibleTargetFramework(framework.Key); if (selectedFramework == null) { root.Reports.WriteError($"Unable to build {project.Name}. It is not compatible with the requested target framework: {framework.Key}"); return false; } buildOptions.TargetFrameworks.Add(selectedFramework.FrameworkName, VersionUtility.GetShortFrameworkName(selectedFramework.FrameworkName)); } } // Mute "dnu pack" completely if it is invoked by "dnu publish --quiet" buildOptions.Reports.Information = root.Reports.Quiet; var buildManager = new BuildManager(root.HostServices, buildOptions); if (!buildManager.Build()) { return false; } // Extract the generated nupkg to target path var srcNupkgPath = Path.Combine(buildOptions.OutputDir, root.Configuration, targetNupkg); var srcSymbolsNupkgPath = Path.ChangeExtension(srcNupkgPath, "symbols.nupkg"); var options = new Packages.AddOptions { NuGetPackage = root.IncludeSymbols ? srcSymbolsNupkgPath : srcNupkgPath, SourcePackages = root.TargetPackagesPath, Reports = root.Reports }; var packagesAddCommand = new Packages.AddCommand(options); packagesAddCommand.Execute().GetAwaiter().GetResult(); // Copy content files (e.g. html, js and images) of main project into "root" folder of the exported package var rootFolderPath = Path.Combine(TargetPath, "root"); var rootProjectJson = Path.Combine(rootFolderPath, Runtime.Project.ProjectFileName); root.Operations.Delete(rootFolderPath); CopyProject(root, project, rootFolderPath, includeSource: false); UpdateWebRoot(root, rootFolderPath); UpdateJson(rootProjectJson, jsonObj => { // Update the project entrypoint jsonObj["entryPoint"] = _projectDescription.Identity.Name; // Set mark this as non loadable jsonObj["loadable"] = false; // Update the dependencies node to reference the main project var deps = new JObject(); jsonObj["dependencies"] = deps; deps[_projectDescription.Identity.Name] = _projectDescription.Identity.Version.ToString(); }); var appBase = Path.Combine(PublishRoot.AppRootName, "packages", resolver.GetPackageDirectory(_projectDescription.Identity.Name, _projectDescription.Identity.Version), "root"); _relativeAppBase = Path.Combine("..", appBase); ApplicationBasePath = Path.Combine(root.OutputPath, appBase); root.Reports.Quiet.WriteLine("Removing {0}", srcNupkgPath); File.Delete(srcNupkgPath); root.Reports.Quiet.WriteLine("Removing {0}", srcSymbolsNupkgPath); File.Delete(srcSymbolsNupkgPath); return true; }
private bool EmitNupkg(PublishRoot root) { root.Reports.Quiet.WriteLine(" Packing nupkg from {0} dependency {1}", _libraryDescription.Type, _libraryDescription.Identity.Name); IsPackage = true; var project = GetCurrentProject(); var resolver = new DefaultPackagePathResolver(root.TargetPackagesPath); var targetNupkg = resolver.GetPackageFileName(project.Name, project.Version); TargetPath = resolver.GetInstallPath(project.Name, project.Version); root.Reports.Quiet.WriteLine(" Source {0}", _libraryDescription.Path.Bold()); root.Reports.Quiet.WriteLine(" Target {0}", TargetPath); if (Directory.Exists(TargetPath)) { root.Operations.Delete(TargetPath); } // Generate nupkg from this project dependency var buildOptions = new BuildOptions(); buildOptions.ProjectPatterns.Add(project.ProjectDirectory); buildOptions.OutputDir = Path.Combine(project.ProjectDirectory, "bin"); buildOptions.Configurations.Add(root.Configuration); buildOptions.GeneratePackages = true; buildOptions.Reports = root.Reports.ShallowCopy(); // Mute "dnu pack" completely if it is invoked by "dnu publish --quiet" buildOptions.Reports.Information = root.Reports.Quiet; var buildManager = new BuildManager(root.HostServices, buildOptions); if (!buildManager.Build()) { return false; } // Extract the generated nupkg to target path var srcNupkgPath = Path.Combine(buildOptions.OutputDir, root.Configuration, targetNupkg); var srcSymbolsNupkgPath = Path.ChangeExtension(srcNupkgPath, "symbols.nupkg"); var options = new Packages.AddOptions { NuGetPackage = root.IncludeSymbols ? srcSymbolsNupkgPath : srcNupkgPath, SourcePackages = root.TargetPackagesPath, Reports = root.Reports }; var packagesAddCommand = new Packages.AddCommand(options); packagesAddCommand.Execute().GetAwaiter().GetResult(); // Copy content files (e.g. html, js and images) of main project into "root" folder of the exported package var rootFolderPath = Path.Combine(TargetPath, "root"); var rootProjectJson = Path.Combine(rootFolderPath, Runtime.Project.ProjectFileName); root.Operations.Delete(rootFolderPath); CopyProject(root, project, rootFolderPath, includeSource: false); UpdateWebRoot(root, rootFolderPath); UpdateJson(rootProjectJson, jsonObj => { // Update the project entrypoint jsonObj["entryPoint"] = _libraryDescription.Identity.Name; // Set mark this as non loadable jsonObj["loadable"] = false; // Update the dependencies node to reference the main project var deps = new JObject(); jsonObj["dependencies"] = deps; deps[_libraryDescription.Identity.Name] = _libraryDescription.Identity.Version.ToString(); }); var appBase = Path.Combine(PublishRoot.AppRootName, "packages", resolver.GetPackageDirectory(_libraryDescription.Identity.Name, _libraryDescription.Identity.Version), "root"); _relativeAppBase = Path.Combine("..", appBase); ApplicationBasePath = Path.Combine(root.OutputPath, appBase); root.Reports.Quiet.WriteLine("Removing {0}", srcNupkgPath); File.Delete(srcNupkgPath); root.Reports.Quiet.WriteLine("Removing {0}", srcSymbolsNupkgPath); File.Delete(srcSymbolsNupkgPath); return true; }