mirror of
https://github.com/2dust/v2rayN.git
synced 2025-08-30 06:46:19 +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.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
|
||||
class Program
|
||||
{
|
||||
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
|
||||
ExecuteDotNetPublish(@".\v2rayN\v2rayN.csproj", "win-x64", outputPath);
|
||||
|
||||
// Publish for Linux
|
||||
ExecuteDotNetPublish(@".\v2rayN.Desktop\v2rayN.Desktop.csproj", "linux-x64", outputPath);
|
||||
|
||||
// Check if the last command was successful
|
||||
if (Process.GetCurrentProcess().ExitCode != 0)
|
||||
// Publish v2rayN project for Windows
|
||||
if (!PublishProject(@"v2rayN\v2rayN.csproj", "win-x64", outputPath, false))
|
||||
{
|
||||
Environment.Exit(Process.GetCurrentProcess().ExitCode);
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
||||
// Remove PDB files if the directory exists
|
||||
if (Directory.Exists(Path.Combine(outputPath, "win-x64")))
|
||||
// Publish v2rayN.Desktop project for Linux
|
||||
if (!PublishProject(@"v2rayN.Desktop\v2rayN.Desktop.csproj", "linux-x64", outputPath, true))
|
||||
{
|
||||
DirectoryInfo winX64Dir = new DirectoryInfo(Path.Combine(outputPath, "win-x64"));
|
||||
foreach (FileInfo file in winX64Dir.GetFiles("*.pdb"))
|
||||
{
|
||||
file.Delete();
|
||||
}
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
||||
if (Directory.Exists(Path.Combine(outputPath, "linux-x64")))
|
||||
{
|
||||
DirectoryInfo linuxX64Dir = new DirectoryInfo(Path.Combine(outputPath, "linux-x64"));
|
||||
foreach (FileInfo file in linuxX64Dir.GetFiles("*.pdb"))
|
||||
{
|
||||
file.Delete();
|
||||
}
|
||||
}
|
||||
// Remove .pdb files if they exist
|
||||
CleanUpPdbFiles(outputPath);
|
||||
|
||||
Console.WriteLine("Build done");
|
||||
|
||||
// List output path contents
|
||||
string[] files = Directory.GetFiles(outputPath);
|
||||
foreach (string file in files)
|
||||
{
|
||||
Console.WriteLine(file);
|
||||
}
|
||||
// List output files
|
||||
ListOutputFiles(outputPath);
|
||||
|
||||
// Compress output files into a zip file
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = "7z",
|
||||
Arguments = $"a v2rayN.zip {outputPath}",
|
||||
RedirectStandardOutput = true,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true
|
||||
}).WaitForExit();
|
||||
// Create zip archive
|
||||
CreateZipArchive(outputPath, "v2rayN.zip");
|
||||
|
||||
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",
|
||||
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,
|
||||
RedirectStandardError = true,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true
|
||||
};
|
||||
|
||||
using (Process process = Process.Start(processStartInfo))
|
||||
using (var process = Process.Start(startInfo))
|
||||
{
|
||||
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