public override bool Execute() { try { #if DEBUG var debugPackTask = Environment.GetEnvironmentVariable("DEBUG_PACK_TASK"); if (!string.IsNullOrEmpty(debugPackTask) && debugPackTask.Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase)) { Debugger.Launch(); } #endif var request = GetRequest(); var logic = PackTaskLogic; PackageBuilder packageBuilder = null; // If packing using a Nuspec file, we don't need to build a PackageBuilder here // as the package builder is built by reading the manifest file later in the code path. // Passing a null package builder for nuspec file code path is perfectly valid. if (string.IsNullOrEmpty(request.NuspecFile)) { packageBuilder = logic.GetPackageBuilder(request); } PackArgs packArgs = logic.GetPackArgs(request); var packRunner = logic.GetPackCommandRunner(request, packArgs, packageBuilder); return(logic.BuildPackage(packRunner)); } catch (Exception ex) { ExceptionUtilities.LogException(ex, Logger); return(false); } }
public override bool Execute() { NuGetVersion version; if (!NuGetVersion.TryParse(PackageVersion, out version)) { throw new ArgumentException(string.Format( CultureInfo.CurrentCulture, Strings.InvalidPackageVersion, PackageVersion)); } var symbolPackageFormat = PackArgs.GetSymbolPackageFormat(MSBuildStringUtility.TrimAndGetNullForEmpty(SymbolPackageFormat)); var nupkgFileName = PackCommandRunner.GetOutputFileName(PackageId, version, isNupkg: true, symbols: false, symbolPackageFormat: symbolPackageFormat); var nuspecFileName = PackCommandRunner.GetOutputFileName(PackageId, version, isNupkg: false, symbols: false, symbolPackageFormat: symbolPackageFormat); var outputs = new List <ITaskItem>(); outputs.Add(new TaskItem(Path.Combine(PackageOutputPath, nupkgFileName))); outputs.Add(new TaskItem(Path.Combine(NuspecOutputPath, nuspecFileName))); if (IncludeSource || IncludeSymbols) { var nupkgSymbolsFileName = PackCommandRunner.GetOutputFileName(PackageId, version, isNupkg: true, symbols: true, symbolPackageFormat: symbolPackageFormat); var nuspecSymbolsFileName = PackCommandRunner.GetOutputFileName(PackageId, version, isNupkg: false, symbols: true, symbolPackageFormat: symbolPackageFormat); outputs.Add(new TaskItem(Path.Combine(PackageOutputPath, nupkgSymbolsFileName))); outputs.Add(new TaskItem(Path.Combine(NuspecOutputPath, nuspecSymbolsFileName))); } OutputPackItems = outputs.ToArray(); return(true); }
public void BuildPackage_WithDefaultExcludes_ExcludesDefaultExcludes() { using (var test = DefaultExclusionsTest.Create()) { var args = new PackArgs() { CurrentDirectory = test.CurrentDirectory.FullName, Exclude = Enumerable.Empty <string>(), Logger = NullLogger.Instance, Path = test.NuspecFile.FullName }; var runner = new PackCommandRunner(args, createProjectFactory: null); runner.BuildPackage(); using (FileStream stream = test.NupkgFile.OpenRead()) using (var package = new ZipArchive(stream, ZipArchiveMode.Read)) { foreach (string unexpectedEntryName in test.UnexpectedEntryNames) { Assert.Equal(0, package.Entries.Count(entry => entry.Name == unexpectedEntryName)); } foreach (string expectedEntryName in test.ExpectedEntryNames) { Assert.Equal(1, package.Entries.Count(entry => entry.Name == expectedEntryName)); } } } }
public static ProjectWrapper ProjectCreator(PackArgs packArgs, string path) { return(new ProjectWrapper(packArgs.MsBuildDirectory.Value, path, packArgs.Properties) { LogLevel = packArgs.LogLevel, Logger = packArgs.Logger, MachineWideSettings = packArgs.MachineWideSettings, }); }
private void InitNuspecOutputPath(IPackTaskRequest <IMSBuildItem> request, PackArgs packArgs) { if (Path.IsPathRooted(request.NuspecOutputPath)) { packArgs.PackTargetArgs.NuspecOutputPath = request.NuspecOutputPath; } else { packArgs.PackTargetArgs.NuspecOutputPath = Path.Combine( packArgs.CurrentDirectory, request.NuspecOutputPath); } }
public PackCommandRunner GetPackCommandRunner( IPackTaskRequest <IMSBuildItem> request, PackArgs packArgs, PackageBuilder packageBuilder) { var runner = new PackCommandRunner( packArgs, MSBuildProjectFactory.ProjectCreator, packageBuilder); runner.GenerateNugetPackage = request.ContinuePackingAfterGeneratingNuspec; return(runner); }
public BaseCommandRunner(BaseArgs baseArgs) { var packArgs = new PackArgs { CurrentDirectory = baseArgs.CurrentDirectory, Logger = baseArgs.Console, Arguments = new string[0], MsBuildDirectory = new Lazy <string>(() => MsBuildUtility.GetMsBuildDirectoryFromMsBuildPath(null, null, baseArgs.Console).Value.Path) }; // Get the input file packArgs.Path = PackCommandRunner.GetInputFile(packArgs); // Set the current directory if the files being packed are in a different directory PackCommandRunner.SetupCurrentDirectory(packArgs); packArgs.Build = false; packArgs.Exclude = new string[0]; switch (baseArgs.Verbosity) { case Verbosity.Detailed: { packArgs.LogLevel = LogLevel.Verbose; break; } case Verbosity.Normal: { packArgs.LogLevel = LogLevel.Information; break; } case Verbosity.Quiet: { packArgs.LogLevel = LogLevel.Minimal; break; } } this._packArgs = packArgs; }
public void PackTask_DelegatesToPackLogic() { // Arrange var packArgs = new PackArgs(); var packageBuilder = new PackageBuilder(); var packCommandRunner = new PackCommandRunner(null, null); IPackTaskRequest <IMSBuildItem> request = null; var logic = new Mock <IPackTaskLogic>(); logic .Setup(x => x.GetPackArgs(It.IsAny <IPackTaskRequest <IMSBuildItem> >())) .Returns(packArgs) .Callback <IPackTaskRequest <IMSBuildItem> >(r => request = r); logic .Setup(x => x.GetPackageBuilder(It.IsAny <IPackTaskRequest <IMSBuildItem> >())) .Returns(packageBuilder); logic .Setup(x => x.GetPackCommandRunner(It.IsAny <IPackTaskRequest <IMSBuildItem> >(), packArgs, packageBuilder)) .Returns(packCommandRunner); var target = new PackTask(); target.PackTaskLogic = logic.Object; // Act var result = target.Execute(); // Assert // We cannot mock the PackCommandRunner because it's not overridable. Assert.False(result); Assert.NotNull(request); logic.Verify(x => x.GetPackArgs(request)); logic.Verify(x => x.GetPackageBuilder(request)); logic.Verify(x => x.GetPackCommandRunner(request, packArgs, packageBuilder)); logic.Verify(x => x.BuildPackage(packCommandRunner)); }
public IProjectFactory CreateProjectFactory(PackArgs packArgs, string path) { var msbuildDirectory = packArgs.MsBuildDirectory.Value; LoadAssemblies(msbuildDirectory); // Create project, allowing for assembly load failures AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(AssemblyResolve); dynamic project; try { var projectCollection = Activator.CreateInstance(_projectCollectionType); project = Activator.CreateInstance( _projectType, path, packArgs.Properties, null, projectCollection); } finally { AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(AssemblyResolve); } return(new ProjectFactory(packArgs.MsBuildDirectory.Value, project) { IsTool = packArgs.Tool, LogLevel = packArgs.LogLevel, Logger = packArgs.Logger, MachineWideSettings = packArgs.MachineWideSettings, Build = packArgs.Build, IncludeReferencedProjects = packArgs.IncludeReferencedProjects, SymbolPackageFormat = packArgs.SymbolPackageFormat }); }
public void RunPackageBuild_WithGenerateNugetPackageFalse_ReturnsTrue() { using (var testDirectory = TestDirectory.Create()) { var args = new PackArgs() { CurrentDirectory = testDirectory.Path, Logger = NullLogger.Instance, PackTargetArgs = new MSBuildPackTargetArgs() { NuspecOutputPath = Path.Combine(testDirectory.Path, "obj", "Debug"), ContentFiles = new Dictionary <string, IEnumerable <ContentMetadata> >() }, Path = string.Empty, Exclude = Array.Empty <string>() }; var packageBuilder = new PackageBuilder() { Id = "test", Version = new NuGetVersion(1, 0, 0), Description = "Testing PackCommandRunner.GenerateNugetPackage = false" }; packageBuilder.Authors.Add("tester"); var runner = new PackCommandRunner(args, MSBuildProjectFactory.ProjectCreator, packageBuilder); runner.GenerateNugetPackage = false; // Act var actual = runner.RunPackageBuild(); // Assert Assert.True(actual, "PackCommandRunner.RunPackageBuild was not successful"); var expectedNuspecPath = Path.Combine(args.PackTargetArgs.NuspecOutputPath, "test.1.0.0.nuspec"); Assert.True(File.Exists(expectedNuspecPath), "nuspec file does not exist"); } }
private Dictionary <string, IEnumerable <ContentMetadata> > ProcessContentToIncludeInPackage( IPackTaskRequest <IMSBuildItem> request, PackArgs packArgs) { // This maps from source path on disk to target path inside the nupkg. var fileModel = new Dictionary <string, IEnumerable <ContentMetadata> >(); if (request.PackageFiles != null) { var excludeFiles = CalculateFilesToExcludeInPack(request); foreach (var packageFile in request.PackageFiles) { var sourcePath = GetSourcePath(packageFile); if (excludeFiles.Contains(sourcePath)) { continue; } var totalContentMetadata = GetContentMetadata(packageFile, sourcePath, packArgs, request.ContentTargetFolders); if (fileModel.ContainsKey(sourcePath)) { var existingContentMetadata = fileModel[sourcePath]; fileModel[sourcePath] = existingContentMetadata.Concat(totalContentMetadata); } else { var existingContentMetadata = new List <ContentMetadata>(); existingContentMetadata.AddRange(totalContentMetadata); fileModel.Add(sourcePath, existingContentMetadata); } } } return(fileModel); }
// The targetpaths returned from this function contain the directory in the nuget package where the file would go to. The filename is added later on to the target path. // whether or not the filename is added later on is dependent upon the fact that does the targetpath resolved here ends with a directory separator char or not. private IEnumerable <ContentMetadata> GetContentMetadata(IMSBuildItem packageFile, string sourcePath, PackArgs packArgs, string[] contentTargetFolders) { var targetPaths = contentTargetFolders .Select(PathUtility.EnsureTrailingSlash) .ToList(); var isPackagePathSpecified = packageFile.Properties.Contains("PackagePath"); // if user specified a PackagePath, then use that. Look for any ** which are indicated by the RecrusiveDir metadata in msbuild. if (isPackagePathSpecified) { // The rule here is that if the PackagePath is an empty string, then we add the file to the root of the package. // Instead if it is a ';' delimited string, then the user needs to specify a '\' to indicate that the file should go to the root of the package. var packagePathString = packageFile.GetProperty("PackagePath"); targetPaths = packagePathString == null ? new string[] { string.Empty }.ToList() : MSBuildStringUtility.Split(packagePathString) .Distinct() .ToList(); var recursiveDir = packageFile.GetProperty("RecursiveDir"); // The below NuGetRecursiveDir workaround needs to be done due to msbuild bug https://github.com/Microsoft/msbuild/issues/3121 recursiveDir = string.IsNullOrEmpty(recursiveDir) ? packageFile.GetProperty("NuGetRecursiveDir") : recursiveDir; if (!string.IsNullOrEmpty(recursiveDir)) { var newTargetPaths = new List <string>(); var fileName = Path.GetFileName(sourcePath); foreach (var targetPath in targetPaths) { newTargetPaths.Add(PathUtility.GetStringComparerBasedOnOS(). Compare(Path.GetExtension(fileName), Path.GetExtension(targetPath)) == 0 && !string.IsNullOrEmpty(Path.GetExtension(fileName)) ? targetPath : Path.Combine(targetPath, recursiveDir)); } targetPaths = newTargetPaths; } } var buildActionString = packageFile.GetProperty("BuildAction"); var buildAction = BuildAction.Parse(string.IsNullOrEmpty(buildActionString) ? "None" : buildActionString); // TODO: Do the work to get the right language of the project, tracked via https://github.com/NuGet/Home/issues/4100 var language = buildAction.Equals(BuildAction.Compile) ? "cs" : "any"; var setOfTargetPaths = new HashSet <string>(targetPaths, PathUtility.GetStringComparerBasedOnOS()); // If package path wasn't specified, then we expand the "contentFiles" value we // got from ContentTargetFolders and expand it to contentFiles/any/<TFM>/ if (!isPackagePathSpecified) { if (setOfTargetPaths.Remove("contentFiles" + Path.DirectorySeparatorChar) || setOfTargetPaths.Remove("contentFiles")) { foreach (var framework in packArgs.PackTargetArgs.TargetFrameworks) { setOfTargetPaths.Add(PathUtility.EnsureTrailingSlash( Path.Combine("contentFiles", language, framework.GetShortFolderName() ))); } } } // this if condition means there is no package path provided, file is within the project directory // and the target path should preserve this relative directory structure. // This case would be something like : // <Content Include= "folderA\folderB\abc.txt"> // Since the package path wasn't specified, we will add this to the package paths obtained via ContentTargetFolders and preserve // relative directory structure if (!isPackagePathSpecified && sourcePath.StartsWith(packArgs.CurrentDirectory, StringComparison.CurrentCultureIgnoreCase) && !Path.GetFileName(sourcePath) .Equals(packageFile.GetProperty(IdentityProperty), StringComparison.CurrentCultureIgnoreCase)) { var newTargetPaths = new List <string>(); var identity = packageFile.GetProperty(IdentityProperty); // Identity can be a rooted absolute path too, in which case find the path relative to the current directory if (Path.IsPathRooted(identity)) { identity = PathUtility.GetRelativePath(PathUtility.EnsureTrailingSlash(packArgs.CurrentDirectory), identity); identity = Path.GetDirectoryName(identity); } // If identity is not a rooted path, then it is a relative path to the project directory else if (identity.EndsWith(Path.GetFileName(sourcePath), StringComparison.CurrentCultureIgnoreCase)) { identity = Path.GetDirectoryName(identity); } foreach (var targetPath in setOfTargetPaths) { var newTargetPath = Path.Combine(targetPath, identity); // We need to do this because evaluated identity in the above line of code can be an empty string // in the case when the original identity string was the absolute path to a file in project directory, and is in // the same directory as the csproj file. newTargetPath = PathUtility.EnsureTrailingSlash(newTargetPath); newTargetPaths.Add(newTargetPath); } setOfTargetPaths = new HashSet <string>(newTargetPaths, PathUtility.GetStringComparerBasedOnOS()); } // we take the final set of evaluated target paths and append the file name to it if not // already done. we check whether the extension of the target path is the same as the extension // of the source path and add the filename accordingly. var totalSetOfTargetPaths = new List <string>(); foreach (var targetPath in setOfTargetPaths) { var currentPath = targetPath; var fileName = Path.GetFileName(sourcePath); if (string.IsNullOrEmpty(Path.GetExtension(fileName)) || !Path.GetExtension(fileName) .Equals(Path.GetExtension(targetPath), StringComparison.OrdinalIgnoreCase)) { currentPath = Path.Combine(targetPath, fileName); } totalSetOfTargetPaths.Add(currentPath); } return(totalSetOfTargetPaths.Select(target => new ContentMetadata() { BuildAction = buildAction.Value, Source = sourcePath, Target = target, CopyToOutput = packageFile.GetProperty("PackageCopyToOutput"), Flatten = packageFile.GetProperty("PackageFlatten") })); }
public static void Register(CommandLineApplication app, Func <ILogger> getLogger) { app.Command("pack", pack => { pack.Description = Strings.PackCommand_Description; pack.Option( CommandConstants.ForceEnglishOutputOption, Strings.ForceEnglishOutput_Description, CommandOptionType.NoValue); var basePath = pack.Option( "-b|--base-path <basePath>", Strings.BasePath_Description, CommandOptionType.SingleValue); var build = pack.Option( "--build", Strings.Build_Description, CommandOptionType.NoValue); var exclude = pack.Option( "--exclude", Strings.Exclude_Description, CommandOptionType.MultipleValue); var excludeEmpty = pack.Option( "-e|--exclude-empty-directories", Strings.ExcludeEmptyDirectories_Description, CommandOptionType.NoValue); var minClientVersion = pack.Option( "--min-client-version <version>", Strings.MinClientVersion_Description, CommandOptionType.SingleValue); var noDefaultExcludes = pack.Option( "--no-default-excludes", Strings.NoDefaultExcludes_Description, CommandOptionType.NoValue); var noPackageAnalysis = pack.Option( "--no-package-analysis", Strings.NoPackageAnalysis_Description, CommandOptionType.NoValue); var outputDirectory = pack.Option( "-o|--output-directory <outputDirectory>", Strings.OutputDirectory_Description, CommandOptionType.SingleValue); var properties = pack.Option( "-p|--properties <properties>", Strings.OutputDirectory_Description, CommandOptionType.SingleValue); var suffix = pack.Option( "--suffix <suffix>", Strings.Suffix_Description, CommandOptionType.SingleValue); var symbols = pack.Option( "-s|--symbols", Strings.Symbols_Description, CommandOptionType.NoValue); var verbosity = pack.Option( "--verbosity <level>", Strings.Switch_Verbosity, CommandOptionType.SingleValue); var versionOption = pack.Option( "-v|--version <version>", Strings.Version_Description, CommandOptionType.SingleValue); var arguments = pack.Argument( "nuspec or project.json file", Strings.InputFile_Description, multipleValues: true); pack.OnExecute(() => { var logger = getLogger(); var packArgs = new PackArgs(); packArgs.Logger = logger; packArgs.Arguments = arguments.Values; packArgs.Path = PackCommandRunner.GetInputFile(packArgs); // Set the current directory if the files being packed are in a different directory PackCommandRunner.SetupCurrentDirectory(packArgs); logger.LogInformation(string.Format(CultureInfo.CurrentCulture, Strings.PackageCommandAttemptingToBuildPackage, Path.GetFileName(packArgs.Path))); // If the BasePath is not specified, use the directory of the input file (nuspec / proj) file packArgs.BasePath = !basePath.HasValue() ? Path.GetDirectoryName(Path.GetFullPath(packArgs.Path)) : basePath.Value(); packArgs.BasePath = packArgs.BasePath.TrimEnd(Path.DirectorySeparatorChar); packArgs.Build = build.HasValue(); packArgs.Exclude = exclude.Values; packArgs.ExcludeEmptyDirectories = excludeEmpty.HasValue(); packArgs.LogLevel = XPlatUtility.GetLogLevel(verbosity); if (minClientVersion.HasValue()) { Version version; if (!Version.TryParse(minClientVersion.Value(), out version)) { throw new ArgumentException(Strings.PackageCommandInvalidMinClientVersion); } packArgs.MinClientVersion = version; } packArgs.MachineWideSettings = new CommandLineXPlatMachineWideSetting(); packArgs.MsBuildDirectory = new Lazy <string>(() => string.Empty); packArgs.NoDefaultExcludes = noDefaultExcludes.HasValue(); packArgs.NoPackageAnalysis = noPackageAnalysis.HasValue(); packArgs.OutputDirectory = outputDirectory.Value(); if (properties.HasValue()) { foreach (var property in properties.Value().Split(';')) { int index = property.IndexOf('='); if (index > 0 && index < property.Length - 1) { packArgs.Properties.Add(property.Substring(0, index), property.Substring(index + 1)); } } } packArgs.Suffix = suffix.Value(); packArgs.Symbols = symbols.HasValue(); if (versionOption.HasValue()) { NuGetVersion version; if (!NuGetVersion.TryParse(versionOption.Value(), out version)) { throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Strings.PackageVersionInvalid, versionOption.Value())); } packArgs.Version = version.ToNormalizedString(); } PackCommandRunner packCommandRunner = new PackCommandRunner(packArgs, null); packCommandRunner.BuildPackage(); return(0); }); }); }
private void InitCurrentDirectoryAndFileName(IPackTaskRequest <IMSBuildItem> request, PackArgs packArgs) { if (request.PackItem == null) { throw new PackagingException(NuGetLogCode.NU5028, Strings.NoPackItemProvided); } packArgs.CurrentDirectory = Path.Combine( request.PackItem.GetProperty("RootDir"), request.PackItem.GetProperty("Directory")).TrimEnd(Path.DirectorySeparatorChar); packArgs.Arguments = new string[] { !string.IsNullOrEmpty(request.NuspecFile) ? request.NuspecFile : string.Concat(request.PackItem.GetProperty("FileName"), request.PackItem.GetProperty("Extension")) }; packArgs.Path = !string.IsNullOrEmpty(request.NuspecFile) ? request.NuspecFile : request.PackItem.GetProperty("FullPath"); packArgs.Exclude = new HashSet <string>(StringComparer.OrdinalIgnoreCase); }
public PackArgs GetPackArgs(IPackTaskRequest <IMSBuildItem> request) { var packArgs = new PackArgs { Logger = request.Logger, OutputDirectory = request.PackageOutputPath, Serviceable = request.Serviceable, Tool = request.IsTool, Symbols = request.IncludeSymbols, BasePath = request.NuspecBasePath, NoPackageAnalysis = request.NoPackageAnalysis, PackTargetArgs = new MSBuildPackTargetArgs { TargetPathsToAssemblies = InitLibFiles(request.BuildOutputInPackage), TargetPathsToSymbols = InitLibFiles(request.TargetPathsToSymbols), AssemblyName = request.AssemblyName, IncludeBuildOutput = request.IncludeBuildOutput, BuildOutputFolder = request.BuildOutputFolder, TargetFrameworks = ParseFrameworks(request) } }; if (request.MinClientVersion != null) { Version version; if (!Version.TryParse(request.MinClientVersion, out version)) { throw new ArgumentException(string.Format( CultureInfo.CurrentCulture, Strings.InvalidMinClientVersion, request.MinClientVersion)); } packArgs.MinClientVersion = version; } if (request.NuspecProperties != null && request.NuspecProperties.Any()) { packArgs.Properties.AddRange(ParsePropertiesAsDictionary(request.NuspecProperties)); if (packArgs.Properties.ContainsKey("version")) { packArgs.Version = packArgs.Properties["version"]; } } InitCurrentDirectoryAndFileName(request, packArgs); InitNuspecOutputPath(request, packArgs); if (request.IncludeSource) { packArgs.PackTargetArgs.SourceFiles = GetSourceFiles(request, packArgs.CurrentDirectory); packArgs.Symbols = request.IncludeSource; } PackCommandRunner.SetupCurrentDirectory(packArgs); var contentFiles = ProcessContentToIncludeInPackage(request, packArgs); packArgs.PackTargetArgs.ContentFiles = contentFiles; return(packArgs); }
public PackArgs GetPackArgs(IPackTaskRequest <IMSBuildItem> request) { var packArgs = new PackArgs { InstallPackageToOutputPath = request.InstallPackageToOutputPath, OutputFileNamesWithoutVersion = request.OutputFileNamesWithoutVersion, OutputDirectory = request.PackageOutputPath, Serviceable = request.Serviceable, Tool = request.IsTool, Symbols = request.IncludeSymbols, SymbolPackageFormat = PackArgs.GetSymbolPackageFormat(request.SymbolPackageFormat), BasePath = request.NuspecBasePath, NoPackageAnalysis = request.NoPackageAnalysis, NoDefaultExcludes = request.NoDefaultExcludes, WarningProperties = WarningProperties.GetWarningProperties(request.TreatWarningsAsErrors, request.WarningsAsErrors, request.NoWarn), PackTargetArgs = new MSBuildPackTargetArgs() }; packArgs.Logger = new PackCollectorLogger(request.Logger, packArgs.WarningProperties); if (request.MinClientVersion != null) { Version version; if (!Version.TryParse(request.MinClientVersion, out version)) { throw new PackagingException(NuGetLogCode.NU5022, string.Format( CultureInfo.CurrentCulture, Strings.InvalidMinClientVersion, request.MinClientVersion)); } packArgs.MinClientVersion = version; } InitCurrentDirectoryAndFileName(request, packArgs); InitNuspecOutputPath(request, packArgs); PackCommandRunner.SetupCurrentDirectory(packArgs); if (!string.IsNullOrEmpty(request.NuspecFile)) { if (request.NuspecProperties != null && request.NuspecProperties.Any()) { packArgs.Properties.AddRange(ParsePropertiesAsDictionary(request.NuspecProperties)); if (packArgs.Properties.ContainsKey("version")) { packArgs.Version = packArgs.Properties["version"]; } } } else { // This only needs to happen when packing via csproj, not nuspec. packArgs.PackTargetArgs.AllowedOutputExtensionsInPackageBuildOutputFolder = InitOutputExtensions(request.AllowedOutputExtensionsInPackageBuildOutputFolder); packArgs.PackTargetArgs.AllowedOutputExtensionsInSymbolsPackageBuildOutputFolder = InitOutputExtensions(request.AllowedOutputExtensionsInSymbolsPackageBuildOutputFolder); packArgs.PackTargetArgs.TargetPathsToAssemblies = InitLibFiles(request.BuildOutputInPackage); packArgs.PackTargetArgs.TargetPathsToSymbols = InitLibFiles(request.TargetPathsToSymbols); packArgs.PackTargetArgs.AssemblyName = request.AssemblyName; packArgs.PackTargetArgs.IncludeBuildOutput = request.IncludeBuildOutput; packArgs.PackTargetArgs.BuildOutputFolder = request.BuildOutputFolders; packArgs.PackTargetArgs.TargetFrameworks = ParseFrameworks(request); if (request.IncludeSource) { packArgs.PackTargetArgs.SourceFiles = GetSourceFiles(request, packArgs.CurrentDirectory); packArgs.Symbols = request.IncludeSource; } var contentFiles = ProcessContentToIncludeInPackage(request, packArgs); packArgs.PackTargetArgs.ContentFiles = contentFiles; } return(packArgs); }
public override void ExecuteCommand() { var packArgs = new PackArgs(); packArgs.Logger = Console; packArgs.Arguments = Arguments; packArgs.OutputDirectory = OutputDirectory; packArgs.BasePath = BasePath; packArgs.MsBuildDirectory = new Lazy <string>(() => MsBuildUtility.GetMsBuildDirectoryFromMsBuildPath(MSBuildPath, MSBuildVersion, Console).Value.Path); if (!string.IsNullOrEmpty(PackagesDirectory)) { packArgs.PackagesDirectory = Path.GetFullPath(PackagesDirectory); } if (!string.IsNullOrEmpty(SolutionDirectory)) { packArgs.SolutionDirectory = Path.GetFullPath(SolutionDirectory); } // Get the input file packArgs.Path = PackCommandRunner.GetInputFile(packArgs); // Set the current directory if the files being packed are in a different directory PackCommandRunner.SetupCurrentDirectory(packArgs); Console.WriteLine(LocalizedResourceManager.GetString("PackageCommandAttemptingToBuildPackage"), Path.GetFileName(packArgs.Path)); if (!string.IsNullOrEmpty(MinClientVersion)) { if (!System.Version.TryParse(MinClientVersion, out _minClientVersionValue)) { throw new CommandLineException(LocalizedResourceManager.GetString("PackageCommandInvalidMinClientVersion")); } } if (!string.IsNullOrEmpty(SymbolPackageFormat)) { packArgs.SymbolPackageFormat = PackArgs.GetSymbolPackageFormat(SymbolPackageFormat); } packArgs.Deterministic = Deterministic; packArgs.Build = Build; packArgs.Exclude = Exclude; packArgs.ExcludeEmptyDirectories = ExcludeEmptyDirectories; packArgs.IncludeReferencedProjects = IncludeReferencedProjects; switch (Verbosity) { case Verbosity.Detailed: { packArgs.LogLevel = LogLevel.Verbose; break; } case Verbosity.Normal: { packArgs.LogLevel = LogLevel.Information; break; } case Verbosity.Quiet: { packArgs.LogLevel = LogLevel.Minimal; break; } } packArgs.MinClientVersion = _minClientVersionValue; packArgs.NoDefaultExcludes = NoDefaultExcludes; packArgs.NoPackageAnalysis = NoPackageAnalysis; if (Properties.Any()) { packArgs.Properties.AddRange(Properties); } packArgs.Suffix = Suffix; packArgs.Symbols = Symbols; packArgs.Tool = Tool; packArgs.InstallPackageToOutputPath = InstallPackageToOutputPath; packArgs.OutputFileNamesWithoutVersion = OutputFileNamesWithoutVersion; if (!string.IsNullOrEmpty(Version)) { NuGetVersion version; if (!NuGetVersion.TryParse(Version, out version)) { throw new PackagingException(NuGetLogCode.NU5010, string.Format(CultureInfo.CurrentCulture, NuGetResources.InstallCommandPackageReferenceInvalidVersion, Version)); } packArgs.Version = version.ToFullString(); } var packCommandRunner = new PackCommandRunner(packArgs, ProjectFactory.ProjectCreator); packCommandRunner.BuildPackage(); }
public override void ExecuteCommand() { PackArgs packArgs = new PackArgs(); packArgs.Logger = Console; packArgs.Arguments = Arguments; packArgs.OutputDirectory = OutputDirectory; // The directory that contains msbuild packArgs.MsBuildDirectory = new Lazy <string>(() => MsBuildUtility.GetMsbuildDirectory(MSBuildVersion, Console)); // Get the input file packArgs.Path = PackCommandRunner.GetInputFile(packArgs); // Set the current directory if the files being packed are in a different directory PackCommandRunner.SetupCurrentDirectory(packArgs); Console.WriteLine(LocalizedResourceManager.GetString("PackageCommandAttemptingToBuildPackage"), Path.GetFileName(packArgs.Path)); // If the BasePath is not specified, use the directory of the input file (nuspec / proj) file BasePath = String.IsNullOrEmpty(BasePath) ? Path.GetDirectoryName(Path.GetFullPath(packArgs.Path)) : BasePath; BasePath = BasePath.TrimEnd(Path.DirectorySeparatorChar); if (!String.IsNullOrEmpty(MinClientVersion)) { if (!System.Version.TryParse(MinClientVersion, out _minClientVersionValue)) { throw new CommandLineException(LocalizedResourceManager.GetString("PackageCommandInvalidMinClientVersion")); } } packArgs.BasePath = BasePath; packArgs.Build = Build; packArgs.Exclude = Exclude; packArgs.ExcludeEmptyDirectories = ExcludeEmptyDirectories; packArgs.IncludeReferencedProjects = IncludeReferencedProjects; switch (Verbosity) { case Verbosity.Detailed: { packArgs.LogLevel = Common.LogLevel.Verbose; break; } case Verbosity.Normal: { packArgs.LogLevel = Common.LogLevel.Information; break; } case Verbosity.Quiet: { packArgs.LogLevel = Common.LogLevel.Minimal; break; } } packArgs.MinClientVersion = _minClientVersionValue; packArgs.NoDefaultExcludes = NoDefaultExcludes; packArgs.NoPackageAnalysis = NoPackageAnalysis; if (Properties.Any()) { packArgs.Properties.AddRange(Properties); } packArgs.Suffix = Suffix; packArgs.Symbols = Symbols; packArgs.Tool = Tool; if (!string.IsNullOrEmpty(Version)) { NuGetVersion version; if (!NuGetVersion.TryParse(Version, out version)) { throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, NuGetResources.InstallCommandPackageReferenceInvalidVersion, Version)); } packArgs.Version = version.ToNormalizedString(); } PackCommandRunner packCommandRunner = new PackCommandRunner(packArgs, ProjectFactory.ProjectCreator); packCommandRunner.BuildPackage(); }