mirror of
https://github.com/2dust/v2rayN.git
synced 2025-08-30 23:06:20 +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 (
|
// This code is for .NET CLI tool usage with C#
|
||||||
[Parameter()]
|
|
||||||
[ValidateNotNullOrEmpty()]
|
|
||||||
[string]
|
|
||||||
$OutputPath = '.\bin\v2rayN'
|
|
||||||
)
|
|
||||||
|
|
||||||
Write-Host 'Building'
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
dotnet publish `
|
class Program
|
||||||
.\v2rayN\v2rayN.csproj `
|
{
|
||||||
-c Release `
|
static void Main(string[] args)
|
||||||
-r win-x64 `
|
{
|
||||||
--self-contained false `
|
string outputPath = @".\bin\v2rayN"; // Default output path
|
||||||
-p:PublishReadyToRun=false `
|
|
||||||
-p:PublishSingleFile=true `
|
|
||||||
-o "$OutputPath\win-x64"
|
|
||||||
|
|
||||||
dotnet publish `
|
Console.WriteLine("Building");
|
||||||
.\v2rayN.Desktop\v2rayN.Desktop.csproj `
|
|
||||||
-c Release `
|
|
||||||
-r linux-x64 `
|
|
||||||
--self-contained true `
|
|
||||||
-p:PublishReadyToRun=false `
|
|
||||||
-p:PublishSingleFile=true `
|
|
||||||
-o "$OutputPath\linux-x64"
|
|
||||||
|
|
||||||
|
// Publish for Windows
|
||||||
|
ExecuteDotNetPublish(@".\v2rayN\v2rayN.csproj", "win-x64", outputPath);
|
||||||
|
|
||||||
|
// Publish for Linux
|
||||||
|
ExecuteDotNetPublish(@".\v2rayN.Desktop\v2rayN.Desktop.csproj", "linux-x64", outputPath);
|
||||||
|
|
||||||
if ( -Not $? ) {
|
// Check if the last command was successful
|
||||||
exit $lastExitCode
|
if (Process.GetCurrentProcess().ExitCode != 0)
|
||||||
}
|
{
|
||||||
|
Environment.Exit(Process.GetCurrentProcess().ExitCode);
|
||||||
|
}
|
||||||
|
|
||||||
if ( Test-Path -Path .\bin\v2rayN ) {
|
// Remove PDB files if the directory exists
|
||||||
rm -Force "$OutputPath\win-x64\*.pdb"
|
if (Directory.Exists(Path.Combine(outputPath, "win-x64")))
|
||||||
rm -Force "$OutputPath\linux-x64\*.pdb"
|
{
|
||||||
|
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