protected override void DoExecute(ITaskContext context) { FindNuGetPackageInUserRepositoryTask findPackageTask = new FindNuGetPackageInUserRepositoryTask(packageId); findPackageTask.Execute(context); if (findPackageTask.PackageVersion != null && packageVersion != null && findPackageTask.PackageVersion > packageVersion) { packageDirectory = findPackageTask.PackageDirectory; return; } if (findPackageTask.PackageDirectory != null) { packageDirectory = findPackageTask.PackageDirectory; return; } NuGetCmdLineTask task = new NuGetCmdLineTask("install") .AddArgument(packageId) .AddArgument("-Source").AddArgument(packageSource) .AddArgument("-NonInteractive") .AddArgument("-OutputDirectory").AddArgument(NuGetPackagesCacheDir); if (packageVersion != null) { task.AddArgument("-Version").AddArgument(packageVersion.ToString()); } if (configFile != null) { task.AddArgument("-ConfigFile").AddArgument(configFile); } if (verbosity.HasValue) { task.AddVerbosityArgument(verbosity.Value); } task.Execute(context); findPackageTask.Execute(context); packageDirectory = findPackageTask.PackageDirectory; if (packageDirectory == null) { context.Fail( "Something is wrong, after downloading it the NuGet package '{0}' still could not be found.", packageId); } else { context.WriteInfo("Package downloaded to '{0}'", packageDirectory); } }
protected override void DoExecute(ITaskContext context) { FullPath packagesDir = new FullPath(context.Properties.Get(BuildProps.ProductRootDir, ".")); packagesDir = packagesDir.CombineWith(context.Properties.Get <string> (BuildProps.BuildDir)); FileFullPath destNuspecFile = packagesDir.AddFileName("{0}.nuspec", packageId); context.WriteInfo("Preparing the {0} file", destNuspecFile); ReplaceTokensTask task = new ReplaceTokensTask( nuspecFileName, destNuspecFile.ToString()); task.AddTokenValue("version", context.Properties.Get <Version> (BuildProps.BuildVersion).ToString()); task.Execute(context); // package it context.WriteInfo("Creating a NuGet package file"); string nugetWorkingDir = destNuspecFile.Directory.ToString(); NuGetCmdLineTask nugetTask = new NuGetCmdLineTask("pack", nugetWorkingDir); nugetTask .AddArgument(destNuspecFile.FileName); nugetTask.AddVerbosityArgument(NuGetCmdLineTask.NuGetVerbosity.Detailed); if (BasePath != null) { nugetTask.AddArgument("-BasePath").AddArgument(BasePath); } nugetTask.Execute(context); string nupkgFileName = ConstructNupkgFileName(context); context.WriteInfo("NuGet package file {0} created", nupkgFileName); // do not push new packages from a local build if (context.IsInteractive && !AllowPushOnInteractiveBuild) { return; } if (apiKeyFunc == null) { throw new InvalidOperationException("NuGet API key was not provided"); } string apiKey = apiKeyFunc(context); if (apiKey == null) { context.WriteInfo("API key function returned null, skipping pushing of the NuGet package."); return; } // publish the package file context.WriteInfo("Pushing the NuGet package to the repository"); nugetTask = new NuGetCmdLineTask("push", nugetWorkingDir); nugetTask .AddArgument(nupkgFileName) .AddArgument(apiKey) .AddArgument("-Source").AddArgument(nuGetServerUrl) .AddVerbosityArgument(NuGetCmdLineTask.NuGetVerbosity.Detailed); nugetTask .Execute(context); }