mirror of
https://github.com/2dust/v2rayN.git
synced 2025-08-31 07:16:20 +00:00
Update build.cs
This commit is contained in:
parent
5f20b66156
commit
8ed0680507
1 changed files with 79 additions and 47 deletions
126
v2rayN/build.cs
126
v2rayN/build.cs
|
@ -1,84 +1,116 @@
|
||||||
// This code is for .NET CLI tool usage with C#
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.IO.Compression;
|
||||||
|
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
string outputPath = @".\bin\v2rayN"; // Default output path
|
string outputPath = args.Length > 0 ? args[0] : Path.Combine(Directory.GetCurrentDirectory(), "bin", "v2rayN");
|
||||||
|
|
||||||
Console.WriteLine("Building");
|
Console.WriteLine("Building...");
|
||||||
|
|
||||||
// Publish for Windows
|
// Publish v2rayN project for Windows
|
||||||
ExecuteDotNetPublish(@".\v2rayN\v2rayN.csproj", "win-x64", outputPath);
|
if (!PublishProject(@"v2rayN\v2rayN.csproj", "win-x64", outputPath, false))
|
||||||
|
|
||||||
// Publish for Linux
|
|
||||||
ExecuteDotNetPublish(@".\v2rayN.Desktop\v2rayN.Desktop.csproj", "linux-x64", outputPath);
|
|
||||||
|
|
||||||
// Check if the last command was successful
|
|
||||||
if (Process.GetCurrentProcess().ExitCode != 0)
|
|
||||||
{
|
{
|
||||||
Environment.Exit(Process.GetCurrentProcess().ExitCode);
|
Environment.Exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove PDB files if the directory exists
|
// Publish v2rayN.Desktop project for Linux
|
||||||
if (Directory.Exists(Path.Combine(outputPath, "win-x64")))
|
if (!PublishProject(@"v2rayN.Desktop\v2rayN.Desktop.csproj", "linux-x64", outputPath, true))
|
||||||
{
|
{
|
||||||
DirectoryInfo winX64Dir = new DirectoryInfo(Path.Combine(outputPath, "win-x64"));
|
Environment.Exit(1);
|
||||||
foreach (FileInfo file in winX64Dir.GetFiles("*.pdb"))
|
|
||||||
{
|
|
||||||
file.Delete();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Directory.Exists(Path.Combine(outputPath, "linux-x64")))
|
// Remove .pdb files if they exist
|
||||||
{
|
CleanUpPdbFiles(outputPath);
|
||||||
DirectoryInfo linuxX64Dir = new DirectoryInfo(Path.Combine(outputPath, "linux-x64"));
|
|
||||||
foreach (FileInfo file in linuxX64Dir.GetFiles("*.pdb"))
|
|
||||||
{
|
|
||||||
file.Delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine("Build done");
|
Console.WriteLine("Build done");
|
||||||
|
|
||||||
// List output path contents
|
// List output files
|
||||||
string[] files = Directory.GetFiles(outputPath);
|
ListOutputFiles(outputPath);
|
||||||
foreach (string file in files)
|
|
||||||
{
|
|
||||||
Console.WriteLine(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compress output files into a zip file
|
// Create zip archive
|
||||||
Process.Start(new ProcessStartInfo
|
CreateZipArchive(outputPath, "v2rayN.zip");
|
||||||
{
|
|
||||||
FileName = "7z",
|
|
||||||
Arguments = $"a v2rayN.zip {outputPath}",
|
|
||||||
RedirectStandardOutput = true,
|
|
||||||
UseShellExecute = false,
|
|
||||||
CreateNoWindow = true
|
|
||||||
}).WaitForExit();
|
|
||||||
|
|
||||||
Environment.Exit(0);
|
Environment.Exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ExecuteDotNetPublish(string projectPath, string runtimeIdentifier, string outputPath)
|
static bool PublishProject(string projectPath, string runtimeIdentifier, string outputPath, bool selfContained)
|
||||||
{
|
{
|
||||||
ProcessStartInfo processStartInfo = new ProcessStartInfo
|
var startInfo = new ProcessStartInfo
|
||||||
{
|
{
|
||||||
FileName = "dotnet",
|
FileName = "dotnet",
|
||||||
Arguments = $"publish \"{projectPath}\" -c Release -r {runtimeIdentifier} --self-contained false -p:PublishReadyToRun=false -p:PublishSingleFile=true -o \"{Path.Combine(outputPath, runtimeIdentifier)}\"",
|
Arguments = $"publish \"{projectPath}\" -c Release -r {runtimeIdentifier} --self-contained {selfContained.ToString().ToLower()} -p:PublishReadyToRun=false -p:PublishSingleFile=true -o \"{Path.Combine(outputPath, runtimeIdentifier)}\"",
|
||||||
RedirectStandardOutput = true,
|
RedirectStandardOutput = true,
|
||||||
|
RedirectStandardError = true,
|
||||||
UseShellExecute = false,
|
UseShellExecute = false,
|
||||||
CreateNoWindow = true
|
CreateNoWindow = true
|
||||||
};
|
};
|
||||||
|
|
||||||
using (Process process = Process.Start(processStartInfo))
|
using (var process = Process.Start(startInfo))
|
||||||
{
|
{
|
||||||
process.WaitForExit();
|
process.WaitForExit();
|
||||||
|
string output = process.StandardOutput.ReadToEnd();
|
||||||
|
string error = process.StandardError.ReadToEnd();
|
||||||
|
|
||||||
|
if (process.ExitCode != 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Error publishing {projectPath}: {error}");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Console.WriteLine(output);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void CleanUpPdbFiles(string outputPath)
|
||||||
|
{
|
||||||
|
string winPdbPath = Path.Combine(outputPath, "win-x64");
|
||||||
|
string linuxPdbPath = Path.Combine(outputPath, "linux-x64");
|
||||||
|
|
||||||
|
if (Directory.Exists(winPdbPath))
|
||||||
|
{
|
||||||
|
foreach (var file in Directory.GetFiles(winPdbPath, "*.pdb"))
|
||||||
|
{
|
||||||
|
File.Delete(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Directory.Exists(linuxPdbPath))
|
||||||
|
{
|
||||||
|
foreach (var file in Directory.GetFiles(linuxPdbPath, "*.pdb"))
|
||||||
|
{
|
||||||
|
File.Delete(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ListOutputFiles(string outputPath)
|
||||||
|
{
|
||||||
|
foreach (var dir in Directory.GetDirectories(outputPath))
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Contents of {dir}:");
|
||||||
|
foreach (var file in Directory.GetFiles(dir))
|
||||||
|
{
|
||||||
|
Console.WriteLine($" - {Path.GetFileName(file)}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void CreateZipArchive(string sourceFolder, string zipFileName)
|
||||||
|
{
|
||||||
|
string zipFilePath = Path.Combine(Directory.GetCurrentDirectory(), zipFileName);
|
||||||
|
|
||||||
|
if (File.Exists(zipFilePath))
|
||||||
|
{
|
||||||
|
File.Delete(zipFilePath); // Remove existing zip file
|
||||||
|
}
|
||||||
|
|
||||||
|
ZipFile.CreateFromDirectory(sourceFolder, zipFilePath);
|
||||||
|
|
||||||
|
Console.WriteLine($"Created zip archive: {zipFileName}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue