Skip to content

Commit

Permalink
直接提交代码
Browse files Browse the repository at this point in the history
  • Loading branch information
BinGuoGuo authored Dec 29, 2020
1 parent ee04f97 commit d5d8bba
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 0 deletions.
8 changes: 8 additions & 0 deletions NuGetPusher.csproj
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>
25 changes: 25 additions & 0 deletions NuGetPusher.sln
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
71 changes: 71 additions & 0 deletions ProcessHelper.cs
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);
}
}
}
}
36 changes: 36 additions & 0 deletions Program.cs
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);
}
}
}
}

0 comments on commit d5d8bba

Please sign in to comment.