mirror of
https://github.com/2dust/v2rayN.git
synced 2025-08-30 06:46:19 +00:00
Update build.ps1
Convert PowerShell to c#
This commit is contained in:
parent
57f9c8158e
commit
326cbb0f4f
1 changed files with 77 additions and 35 deletions
112
v2rayN/build.ps1
112
v2rayN/build.ps1
|
@ -1,42 +1,84 @@
|
|||
param (
|
||||
[Parameter()]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
$OutputPath = '.\bin\v2rayN'
|
||||
)
|
||||
// This code is for .NET CLI tool usage with C#
|
||||
|
||||
Write-Host 'Building'
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
dotnet publish `
|
||||
.\v2rayN\v2rayN.csproj `
|
||||
-c Release `
|
||||
-r win-x64 `
|
||||
--self-contained false `
|
||||
-p:PublishReadyToRun=false `
|
||||
-p:PublishSingleFile=true `
|
||||
-o "$OutputPath\win-x64"
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
string outputPath = @".\bin\v2rayN"; // Default output path
|
||||
|
||||
dotnet publish `
|
||||
.\v2rayN.Desktop\v2rayN.Desktop.csproj `
|
||||
-c Release `
|
||||
-r linux-x64 `
|
||||
--self-contained true `
|
||||
-p:PublishReadyToRun=false `
|
||||
-p:PublishSingleFile=true `
|
||||
-o "$OutputPath\linux-x64"
|
||||
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);
|
||||
|
||||
if ( -Not $? ) {
|
||||
exit $lastExitCode
|
||||
}
|
||||
// Check if the last command was successful
|
||||
if (Process.GetCurrentProcess().ExitCode != 0)
|
||||
{
|
||||
Environment.Exit(Process.GetCurrentProcess().ExitCode);
|
||||
}
|
||||
|
||||
if ( Test-Path -Path .\bin\v2rayN ) {
|
||||
rm -Force "$OutputPath\win-x64\*.pdb"
|
||||
rm -Force "$OutputPath\linux-x64\*.pdb"
|
||||
// Remove PDB files if the directory exists
|
||||
if (Directory.Exists(Path.Combine(outputPath, "win-x64")))
|
||||
{
|
||||
DirectoryInfo winX64Dir = new DirectoryInfo(Path.Combine(outputPath, "win-x64"));
|
||||
foreach (FileInfo file in winX64Dir.GetFiles("*.pdb"))
|
||||
{
|
||||
file.Delete();
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine("Build done");
|
||||
|
||||
// List output path contents
|
||||
string[] files = Directory.GetFiles(outputPath);
|
||||
foreach (string file in files)
|
||||
{
|
||||
Console.WriteLine(file);
|
||||
}
|
||||
|
||||
// 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();
|
||||
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
static void ExecuteDotNetPublish(string projectPath, string runtimeIdentifier, string outputPath)
|
||||
{
|
||||
ProcessStartInfo processStartInfo = 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)}\"",
|
||||
RedirectStandardOutput = true,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true
|
||||
};
|
||||
|
||||
using (Process process = Process.Start(processStartInfo))
|
||||
{
|
||||
process.WaitForExit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host 'Build done'
|
||||
|
||||
ls $OutputPath
|
||||
7z a v2rayN.zip $OutputPath
|
||||
exit 0
|
Loading…
Reference in a new issue