protected override int DoExecute(ITaskContextInternal context) { _packagePath.MustNotBeNullOrEmpty("packagePath (path to .nupkg) must not be null or empty."); // do not push new packages from a local build if (context.BuildServers().IsLocalBuild&& _skipPushOnLocalBuild) { context.LogInfo("pushing package on local build is disabled in build script...Skiping."); return(1); } return(base.DoExecute(context)); }
protected override int DoExecute(ITaskContextInternal context) { FullPath packagesDir = new FullPath(context.Properties.Get(BuildProps.ProductRootDir, ".")); packagesDir = packagesDir.CombineWith(context.Properties.Get <string>(DotNetBuildProps.BuildDir)); FileFullPath destNuspecFile = packagesDir.AddFileName("{0}.nuspec", _packageId); DoLogInfo($"Preparing the {destNuspecFile} file"); new ReplaceTokensTask(_nuspecFileName) .Replace("version", context.Properties.GetBuildVersion().BuildVersionWithQuality(3)) .UseToken("$") .ToDestination(destNuspecFile.ToString()) .ExecuteVoid(context); // package it DoLogInfo("Creating a NuGet package file"); string nugetWorkingDir = destNuspecFile.Directory.ToString(); NuGetCmdLineTask nugetTask = new NuGetCmdLineTask("pack", nugetWorkingDir) { Verbosity = NuGetCmdLineTask.NuGetVerbosity.Detailed }; nugetTask.WithArguments(destNuspecFile.FileName); if (BasePath != null) { nugetTask.WithArguments("-BasePath", BasePath); } nugetTask.ExecuteVoid(context); string nupkgFileName = string.Format( CultureInfo.InvariantCulture, "{0}.{1}.nupkg", _packageId, context.Properties.GetBuildVersion().BuildVersionWithQuality(3)); DoLogInfo($"NuGet package file {nupkgFileName} created"); // do not push new packages from a local build if (context.BuildServers().IsLocalBuild&& _skipPushOnLocalBuild) { context.LogInfo("pushing package on local build is disabled in build script...Skiping."); return(1); } if (_apiKeyFunc == null) { throw new InvalidOperationException("NuGet API key was not provided"); } string apiKey = _apiKeyFunc(context); if (apiKey == null) { return(1); } // publish the package file DoLogInfo("Pushing the NuGet package to the repository"); nugetTask = new NuGetCmdLineTask("push", nugetWorkingDir) { Verbosity = NuGetCmdLineTask.NuGetVerbosity.Detailed, ApiKey = apiKey }; if (_nuGetServerUrl != null) { nugetTask.WithArguments("-Source", _nuGetServerUrl); } nugetTask .WithArguments(nupkgFileName) .ExecuteVoid(context); return(0); }