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 void Validate_AssemblyWithValidTFMInPath_NoWarning() { // Arrange var nuspecContent = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<package xmlns=\"http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd\">" + " <metadata>" + " <id>test</id>" + " <version>1.0.0</version>" + " <authors>Unit Test</authors>" + " <description>Sample Description</description>" + " <language>en-US</language>" + " <dependencies>" + " <dependency id=\"System.Collections.Immutable\" version=\"4.3.0\" />" + " </dependencies>" + " </metadata>" + "</package>"; using (var testDirectory = TestDirectory.Create()) { var nuspecPath = Path.Combine(testDirectory, "test.nuspec"); File.AppendAllText(nuspecPath, nuspecContent); // create a random_tfm directory in a lib directory Directory.CreateDirectory(Path.Combine(testDirectory, "lib", "net46")); // place a dll inside the folder var stream = File.Create(Path.Combine(testDirectory, "lib", "net46", "test.dll")); stream.Dispose(); var builder = new PackageBuilder(); var runner = new PackCommandRunner( new PackArgs { CurrentDirectory = testDirectory, OutputDirectory = testDirectory, Path = nuspecPath, Exclude = Array.Empty <string>(), Symbols = true, Logger = NullLogger.Instance }, MSBuildProjectFactory.ProjectCreator, builder); runner.BuildPackage(); var ruleSet = RuleSet.PackageCreationRuleSet; var nupkgPath = Path.Combine(testDirectory, "test.1.0.0.nupkg"); using (var reader = new PackageArchiveReader(nupkgPath)) { var issues = new List <PackagingLogMessage>(); foreach (var rule in ruleSet) { issues.AddRange(rule.Validate(reader).OrderBy(p => p.Code.ToString(), StringComparer.CurrentCulture)); } Assert.False(issues.Any(p => p.Code == NuGetLogCode.NU5103 && p.Message.Contains("'lib' is not recognized as a valid framework name"))); } } }
public void Validate_FileWithEmptyDirectorySymbolWithNoOtherFiles_NoWarning() { // Arrange var nuspecContent = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<package xmlns=\"http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd\">" + " <metadata>" + " <id>test</id>" + " <version>1.0.0</version>" + " <authors>Unit Test</authors>" + " <description>Sample Description</description>" + " <language>en-US</language>" + " </metadata>" + "</package>"; using (var testDirectory = TestDirectory.Create()) { var nuspecPath = Path.Combine(testDirectory, "test.nuspec"); File.AppendAllText(nuspecPath, nuspecContent); // create a directory that contains a _._ file but no other file var toolsPath = Path.Combine(testDirectory, "tools"); Directory.CreateDirectory(toolsPath); var emptyDirFilePath = Path.Combine(toolsPath, "_._"); var stream = File.CreateText(emptyDirFilePath); stream.Dispose(); var builder = new PackageBuilder(); var runner = new PackCommandRunner( new PackArgs { CurrentDirectory = testDirectory, OutputDirectory = testDirectory, Path = nuspecPath, Exclude = Array.Empty <string>(), Symbols = false, Logger = NullLogger.Instance }, MSBuildProjectFactory.ProjectCreator, builder); runner.BuildPackage(); var ruleSet = RuleSet.PackageCreationRuleSet; var nupkgPath = Path.Combine(testDirectory, "test.1.0.0.nupkg"); using (var reader = new PackageArchiveReader(nupkgPath)) { var issues = new List <PackagingLogMessage>(); foreach (var rule in ruleSet) { issues.AddRange(rule.Validate(reader).OrderBy(p => p.Code.ToString(), StringComparer.CurrentCulture)); } Assert.False(issues.Any(p => p.Code == NuGetLogCode.NU5109 && p.Message.Contains(@"The file at 'tools/_._' uses the symbol for empty directory '_._'"))); } } }
public void Validate_NuSpecFileWithNonDefaultProjectUrl_NoWarning() { // Arrange var nuspecContent = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<package xmlns=\"http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd\">" + " <metadata>" + " <id>test</id>" + " <version>1.0.0</version>" + " <authors>Unit Test</authors>" + " <description>Sample Description</description>" + " <language>en-US</language>" + " <projectUrl>http://unit.test</projectUrl>" + " <licenseUrl>http://unit.test</licenseUrl>" + " <iconUrl>http://unit.test</iconUrl>" + " <dependencies>" + " <dependency id=\"System.Collections.Immutable\" version=\"4.3.0\" />" + " </dependencies>" + " </metadata>" + "</package>"; using (var testDirectory = TestDirectory.Create()) { var nuspecPath = Path.Combine(testDirectory, "test.nuspec"); File.AppendAllText(nuspecPath, nuspecContent); var builder = new PackageBuilder(); var runner = new PackCommandRunner( new PackArgs { CurrentDirectory = testDirectory, OutputDirectory = testDirectory, Path = nuspecPath, Exclude = Array.Empty <string>(), Symbols = true, Logger = NullLogger.Instance }, MSBuildProjectFactory.ProjectCreator, builder); runner.BuildPackage(); var ruleSet = RuleSet.PackageCreationRuleSet; var nupkgPath = Path.Combine(testDirectory, "test.1.0.0.nupkg"); using (var reader = new PackageArchiveReader(nupkgPath)) { var issues = new List <PackagingLogMessage>(); foreach (var rule in ruleSet) { issues.AddRange(rule.Validate(reader).OrderBy(p => p.Code.ToString(), StringComparer.CurrentCulture)); } Assert.False(issues.Any(p => p.Code == NuGetLogCode.NU5102)); } } }
public void PackTask_Dispose() { var dir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(dir); var nuspecPath = Path.Combine(dir, "test.nuspec"); File.WriteAllText(nuspecPath, @" <package xmlns=""http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd""> <metadata> <id>Test</id> <summary>Summary</summary> <description>Description</description> <version>1.0.0</version> <authors>Microsoft</authors> <dependencies> <dependency id=""System.Collections.Immutable"" version=""4.3.0"" /> </dependencies> </metadata> </package> "); var builder = new PackageBuilder(); var runner = new PackCommandRunner( new PackArgs { CurrentDirectory = dir, OutputDirectory = dir, Path = nuspecPath, Exclude = Array.Empty <string>(), Symbols = true, Logger = NullLogger.Instance }, MSBuildProjectFactory.ProjectCreator, builder); runner.BuildPackage(); // It should be possible to delete the entire directory. // If this fails the runner left some files open. Directory.Delete(dir, recursive: true); }
public void PackTask_Dispose() { using (var directory = TestDirectory.Create()) { var nuspecPath = Path.Combine(directory, "test.nuspec"); File.WriteAllText(nuspecPath, @" <package xmlns=""http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd""> <metadata> <id>Test</id> <summary>Summary</summary> <description>Description</description> <version>1.0.0</version> <authors>Microsoft</authors> <dependencies> <dependency id=""System.Collections.Immutable"" version=""4.3.0"" /> </dependencies> </metadata> </package> "); var builder = new PackageBuilder(); var runner = new PackCommandRunner( new PackArgs { CurrentDirectory = directory, OutputDirectory = directory, Path = nuspecPath, Exclude = Array.Empty <string>(), Symbols = true, Logger = NullLogger.Instance }, MSBuildProjectFactory.ProjectCreator, builder); runner.BuildPackage(); } }
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(); }
protected override void ProcessRecord() { _path = string.IsNullOrEmpty(_path) ? _literalPath : _path; // Get the .psd1 file or .ps1 file // Returns the name of the file or the name of the directory, depending on path var pkgFileOrDir = new DirectoryInfo(_path); string moduleManifestOrScriptPath; if (isScript) { moduleManifestOrScriptPath = pkgFileOrDir.FullName; pkgName = pkgFileOrDir.Name.Remove(pkgFileOrDir.Name.Length - 4); } else { moduleManifestOrScriptPath = System.IO.Path.Combine(_path, pkgFileOrDir.Name + ".psd1"); // Validate that there's a module manifest if (!File.Exists(moduleManifestOrScriptPath)) { var message = String.Format("No file with a .psd1 extension was found in {0}. Please specify a path to a valid modulemanifest.", moduleManifestOrScriptPath); var ex = new ArgumentException(message); var moduleManifestNotFound = new ErrorRecord(ex, "moduleManifestNotFound", ErrorCategory.ObjectNotFound, null); this.ThrowTerminatingError(moduleManifestNotFound); } pkgName = pkgFileOrDir.Name; } FileInfo moduleFileInfo; moduleFileInfo = new FileInfo(moduleManifestOrScriptPath); // if there's no specified destination path to publish the nupkg, we'll just create a temp folder and delete it later string outputDir = !string.IsNullOrEmpty(_destinationPath) ? _destinationPath : System.IO.Path.Combine(System.IO.Path.GetTempPath(), Guid.NewGuid().ToString()); if (!Directory.Exists(outputDir)) { Directory.CreateDirectory(outputDir); } // if user does not specify that they want to use a nuspec they've created, we'll create a nuspec var dependencies = new Hashtable(); if (string.IsNullOrEmpty(_nuspec)) { _nuspec = createNuspec(outputDir, moduleFileInfo); } else { // Read the nuspec passed in to pull out the dependency information XDocument doc = XDocument.Load(_nuspec); // ex: <version>2.2.1</version> var versionNode = doc.Descendants("version"); NuGetVersion.TryParse(versionNode.FirstOrDefault().Value, out NuGetVersion version); if (version == null) { var message = "Version is not specified in the .nuspec provided. Please provide a valid version in the .nuspec."; var ex = new ArgumentException(message); var versionNotFound = new ErrorRecord(ex, "versionNotFound", ErrorCategory.NotSpecified, null); this.ThrowTerminatingError(versionNotFound); } // ex: <dependency id="Carbon" version="2.9.2" /> var dependencyNode = doc.Descendants("dependency"); foreach (var dep in dependencyNode) { dependencies.Add(dep.Attribute("id"), dep.Attribute("version")); } } // find repository var r = new RespositorySettings(); var repositoryUrl = r.Read(new[] { _repository }); if (!repositoryUrl.Any()) { var message = String.Format("The resource repository '{0}' is not a registered. Please run 'Register-PSResourceRepository' in order to publish to this repository.", _repository); var ex = new ArgumentException(message); var repositoryNotFound = new ErrorRecord(ex, "repositoryNotFound", ErrorCategory.ObjectNotFound, null); this.ThrowTerminatingError(repositoryNotFound); } if (!_skipDependenciesCheck) { // Check to see that all dependencies are in the repository var findHelper = new FindHelper(); foreach (var dependency in dependencies.Keys) { // Need to make individual calls since we're look for exact version numbers or ranges. var depName = new[] { (string)dependency }; var depVersion = (string)dependencies[dependency]; var type = new[] { "module", "script" }; var repository = new[] { _repository }; // Search for and return the dependency if it's in the repository. var dependencyFound = findHelper.beginFindHelper(depName, type, depVersion, true, null, null, repository, _credential, false, false); if (!dependencyFound.Any()) { var message = String.Format("Dependency {0} was not found in repository {1}. Make sure the dependency is published to the repository before publishing this module.", depName, _repository); var ex = new ArgumentException(message); // System.ArgumentException vs PSArgumentException var dependencyNotFound = new ErrorRecord(ex, "DependencyNotFound", ErrorCategory.ObjectNotFound, null); this.ThrowTerminatingError(dependencyNotFound); } } } if (isScript) { File.Copy(_path, System.IO.Path.Combine(outputDir, pkgName + ".ps1"), true); } else { // Create subdirectory structure in temp folder foreach (string dir in System.IO.Directory.GetDirectories(_path, "*", System.IO.SearchOption.AllDirectories)) { var dirName = dir.Substring(_path.Length).Trim(PathSeparators); System.IO.Directory.CreateDirectory(System.IO.Path.Combine(outputDir, dirName)); } // Copy files over to temp folder foreach (string fileNamePath in System.IO.Directory.GetFiles(_path, "*", System.IO.SearchOption.AllDirectories)) { var fileName = fileNamePath.Substring(_path.Length).Trim(PathSeparators); System.IO.File.Copy(fileNamePath, System.IO.Path.Combine(outputDir, fileName)); } } var outputDirectory = System.IO.Path.Combine(outputDir, "nupkg"); // Pack the module or script into a nupkg given a nuspec. var builder = new PackageBuilder(); var runner = new PackCommandRunner( new PackArgs { CurrentDirectory = outputDir, OutputDirectory = outputDirectory, Path = _nuspec, Exclude = _exclude, Symbols = false, Logger = NullLogger.Instance }, MSBuildProjectFactory.ProjectCreator, builder); runner.BuildPackage(); // Push the nupkg to the appropriate repository // Pkg version is parsed from .ps1 file or .psd1 file var fullNupkgPath = System.IO.Path.Combine(outputDirectory, pkgName + "." + pkgVersion.ToNormalizedString() + ".nupkg"); var repoURL = repositoryUrl.First().Properties["Url"].Value.ToString(); var publishLocation = repoURL.EndsWith("/v2", StringComparison.OrdinalIgnoreCase) ? repoURL + "/package" : repoURL; var settings = NuGet.Configuration.Settings.LoadDefaultSettings(null, null, null); NuGet.Common.ILogger log = new NuGetLogger(); PushRunner.Run( Settings.LoadDefaultSettings(root: null, configFileName: null, machineWideSettings: null), new PackageSourceProvider(settings), fullNupkgPath, publishLocation, _APIKey, // api key null, // symbols source null, // symbols api key 0, // timeout false, // disable buffering false, // no symbols // Skip duplicate: if a package and version already exists, skip it and continue with the next package in the push, if any. false, // no skip duplicate false, // enable server endpoint log).GetAwaiter().GetResult(); }
public void BuildPackage(PackCommandRunner runner) { runner.BuildPackage(); }
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); }); }); }
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(); }