-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.30128.74 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NuGetPusher", "NuGetPusher.csproj", "{BCC01FA8-567B-471E-951B-0EE9B5060FC6}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{BCC01FA8-567B-471E-951B-0EE9B5060FC6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{BCC01FA8-567B-471E-951B-0EE9B5060FC6}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{BCC01FA8-567B-471E-951B-0EE9B5060FC6}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{BCC01FA8-567B-471E-951B-0EE9B5060FC6}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {326023DC-73B6-45CF-9D0E-43893DE01D33} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
|
||
namespace NuGetPusher | ||
{ | ||
public static class ProcessHelper | ||
{ | ||
public static Process Run(string exe, string arguments, string workingDirectory = ".", bool waitExit = false) | ||
{ | ||
try | ||
{ | ||
bool redirectStandardOutput = true; | ||
bool redirectStandardError = true; | ||
bool useShellExecute = false; | ||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
{ | ||
redirectStandardOutput = false; | ||
redirectStandardError = false; | ||
useShellExecute = true; | ||
} | ||
|
||
if (waitExit) | ||
{ | ||
redirectStandardOutput = true; | ||
redirectStandardError = true; | ||
useShellExecute = false; | ||
} | ||
|
||
ProcessStartInfo info = new ProcessStartInfo | ||
{ | ||
FileName = exe, | ||
Arguments = arguments, | ||
CreateNoWindow = true, | ||
UseShellExecute = useShellExecute, | ||
WorkingDirectory = workingDirectory, | ||
RedirectStandardOutput = redirectStandardOutput, | ||
RedirectStandardError = redirectStandardError, | ||
}; | ||
|
||
using Process process = Process.Start(info); | ||
|
||
if (waitExit) | ||
{ | ||
process.OutputDataReceived += (sender, e) => | ||
{ | ||
if(null != e) | ||
{ | ||
Console.WriteLine(e.Data); | ||
} | ||
}; | ||
process.BeginOutputReadLine(); | ||
process.WaitForExit(); | ||
if (process.ExitCode != 0) | ||
{ | ||
throw new Exception($"{process.StandardOutput.ReadToEnd()} {process.StandardError.ReadToEnd()}"); | ||
} | ||
} | ||
|
||
return process; | ||
} | ||
catch (Exception e) | ||
{ | ||
throw new Exception($"dir: {Path.GetFullPath(workingDirectory)}, command: {exe} {arguments}", e); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
|
||
namespace NuGetPusher | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
// arg[0] $(ProjectDir)/bin/Debug 发布文件所在目录 | ||
// arg[1] $(TargetPath) 项目程序集路径 | ||
// arg[2] ApiKey 仓库密钥 | ||
// arg[3] Url 仓库地址 | ||
try | ||
{ | ||
|
||
if (args.Length != 4) | ||
throw new Exception($"invalid parameters: {System.Text.Json.JsonSerializer.Serialize(args)}"); | ||
string publishDir = args[0]; | ||
string assemblyFile = args[1]; | ||
string apiKey = args[2]; | ||
string url = args[3]; | ||
|
||
var assemblyName = System.Reflection.AssemblyName.GetAssemblyName(assemblyFile); | ||
var nupkgName = $"{assemblyName.Name}.{assemblyName.Version.ToString(3)}.nupkg"; | ||
var fullName = System.IO.Path.Combine(publishDir, nupkgName); | ||
Console.WriteLine($"nuget push {fullName} {apiKey} -Source {url}"); | ||
ProcessHelper.Run("nuget.exe", $"push {fullName} {apiKey} -Source {url}", waitExit: true); | ||
Console.WriteLine("publish succeed!"); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex.Message); | ||
} | ||
} | ||
} | ||
} |