Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/ElectronNET.API/Runtime/Helpers/UnpackagedDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,20 @@ public static bool CheckIsUnpackaged()
private static bool? CheckUnpackaged2()
{
var dir = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);

// Electron-First packaging mode: the .NET binary is in resources/bin.
if (dir.Name == "bin" && dir.Parent?.Name == "resources")
{
return false;
}

// DotNet-First packaging mode: the Electron host is in the electron subdirectory.
if (dir.GetDirectories().Any(e => e.Name == "electron"))
{
return false;
}

// Development mode: the .electron subdirectory exists.
if (dir.GetDirectories().Any(e => e.Name == ".electron"))
{
return true;
Expand Down Expand Up @@ -106,4 +115,4 @@ public static bool CheckIsUnpackaged()
return null;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,24 @@ protected override async Task StartCore()
}
else
{
dir = dir.Parent!.Parent!;
startCmd = Path.Combine(dir.FullName, this.electronBinaryName);
// DotNet-First packaging mode: the Electron host is in the electron subdirectory.
var electronDir = Path.Combine(dir.FullName, "electron");

if (Directory.Exists(electronDir))
{
// New DotNet-First directory layout.
startCmd = Path.Combine(electronDir, this.electronBinaryName);
workingDir = electronDir;
}
else
{
// Fallback to the legacy Electron-First directory layout.
dir = dir.Parent!.Parent!;
startCmd = Path.Combine(dir.FullName, this.electronBinaryName);
workingDir = dir.FullName;
}

args = $"-dotnetpacked -electronforcedport={this.socketPort:D} " + this.extraArguments;
workingDir = dir.FullName;
}

// We don't await this in order to let the state transition to "Starting"
Expand Down Expand Up @@ -241,4 +255,4 @@ private void Process_Exited(object sender, EventArgs e)
this.TransitionState(LifetimeState.Stopped);
}
}
}
}
4 changes: 2 additions & 2 deletions src/ElectronNET/build/ElectronNET.Core.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<ElectronSplashScreen></ElectronSplashScreen>
<ElectronIcon></ElectronIcon>
<PackageIcon></PackageIcon>
<ElectronPackageId>$(MSBuildProjectName.Replace(".", "-").ToLower())</ElectronPackageId>
<ElectronPackageId Condition="'$(ElectronPackageId)' == ''">$(MSBuildProjectName.Replace(".", "-").ToLower())</ElectronPackageId>
<ElectronBuilderJson>electron-builder.json</ElectronBuilderJson>
<Title>$(MSBuildProjectName)</Title>
<Title Condition="'$(Title)' == ''">$(MSBuildProjectName)</Title>
</PropertyGroup>

<PropertyGroup>
Expand Down
19 changes: 13 additions & 6 deletions src/ElectronNET/build/ElectronNET.LateImport.targets
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
<ElectronCustomHookTsFiles Include="ElectronHostHook\*.ts" />
</ItemGroup>

<!-- Skip Exec commands configuration (default: false) -->
<PropertyGroup>
<ElectronSkipExecCommands Condition="'$(ElectronSkipExecCommands)' == ''">false</ElectronSkipExecCommands>
</PropertyGroup>

<!-- Create variables for our output paths -->
<PropertyGroup>
<ElectronSourceFilesPath>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\..\..\ElectronNET.Host'))</ElectronSourceFilesPath>
Expand Down Expand Up @@ -151,10 +156,12 @@
BeforeTargets="AssignTargetPaths"
DependsOnTargets="ElectronResolvePaths">

<!-- ElectronPublishDir allows overriding the intermediate publish directory -->
<PropertyGroup Condition="'$(UsingMicrosoftNETSdkWeb)' != 'true'">
<_NonIntermediatePublishDir>$(PublishDir)</_NonIntermediatePublishDir>
<PublishUrl>$(PublishDir)</PublishUrl>
<PublishDir>$(IntermediateOutputPath)PubTmp\</PublishDir>
<PublishDir Condition="'$(ElectronPublishDir)' != ''">$(ElectronPublishDir)</PublishDir>
<PublishDir Condition="'$(ElectronPublishDir)' == ''">$(IntermediateOutputPath)PubTmp\</PublishDir>
</PropertyGroup>

<RemoveDir Directories="$(PublishDir);$(PublishUrl)" Condition="'$(UsingMicrosoftNETSdkWeb)' != 'true'" />
Expand Down Expand Up @@ -385,7 +392,7 @@
<ElectronPlatform Condition="'$(ElectronRuntimeIdentifier)' == 'win-x64' OR '$(ElectronRuntimeIdentifier)' == 'win-x86' OR '$(ElectronRuntimeIdentifier)' == 'win-arm64'">win</ElectronPlatform>
<ElectronPlatform Condition="'$(ElectronRuntimeIdentifier)' == 'linux-x64' OR '$(ElectronRuntimeIdentifier)' == 'linux-arm' OR '$(ElectronRuntimeIdentifier)' == 'linux-arm64'">linux</ElectronPlatform>
<ElectronPlatform Condition="'$(ElectronRuntimeIdentifier)' == 'osx-x64' OR '$(ElectronRuntimeIdentifier)' == 'osx-arm64'">mac</ElectronPlatform>

<!-- npm uses different OS names than Electron -->
<NpmOs Condition="'$(ElectronPlatform)' == 'win'">win32</NpmOs>
<NpmOs Condition="'$(ElectronPlatform)' == 'linux'">linux</NpmOs>
Expand All @@ -394,7 +401,7 @@
<!-- npm CPU is same as ElectronArch except for linux-arm -->
<NpmCpu>$(ElectronArch)</NpmCpu>
<NpmCpu Condition="'$(ElectronRuntimeIdentifier)' == 'linux-arm'">arm</NpmCpu>

<_CurrentOSPlatform Condition="$([MSBuild]::IsOSPlatform('Windows'))">win</_CurrentOSPlatform>
<_CurrentOSPlatform Condition="$([MSBuild]::IsOSPlatform('Linux'))">linux</_CurrentOSPlatform>
<_CurrentOSPlatform Condition="$([MSBuild]::IsOSPlatform('OSX'))">mac</_CurrentOSPlatform>
Expand Down Expand Up @@ -445,7 +452,7 @@

<Message Importance="High" Text="Running command: $(_NpmCmd) in folder: $(ElectronOutputPath)" Condition="@(_CopiedFiles->Count()) > 0" />

<Exec Command="$(_NpmCmd)" WorkingDirectory="$(ElectronOutputPath)" Timeout="600000" StandardOutputImportance="High" StandardErrorImportance="High" ContinueOnError="false" Condition="@(_CopiedFiles->Count()) > 0">
<Exec Command="$(_NpmCmd)" WorkingDirectory="$(ElectronOutputPath)" Timeout="600000" StandardOutputImportance="High" StandardErrorImportance="High" ContinueOnError="false" Condition="'$(ElectronSkipExecCommands)' != 'true' AND @(_CopiedFiles->Count()) > 0">
<Output TaskParameter="ExitCode" PropertyName="ExecExitCode"/>
</Exec>

Expand Down Expand Up @@ -629,7 +636,7 @@ For more information, see: https://github.com/ElectronNET/Electron.NET/wiki/Migr
<_NpmCmd Condition="'$(IsLinuxWsl)' == 'true'">wsl bash -ic '$(_NpmCmd)'</_NpmCmd>
</PropertyGroup>

<Exec Command="$(_NpmCmd)" WorkingDirectory="$(ElectronPublishDirFullPath)" Timeout="600000" StandardOutputImportance="High" StandardErrorImportance="High" ContinueOnError="false" Condition="@(CopiedFiles->Count()) > 0">
<Exec Command="$(_NpmCmd)" WorkingDirectory="$(ElectronPublishDirFullPath)" Timeout="600000" StandardOutputImportance="High" StandardErrorImportance="High" ContinueOnError="false" Condition="'$(ElectronSkipExecCommands)' != 'true' AND @(CopiedFiles->Count()) > 0">
<Output TaskParameter="ExitCode" PropertyName="ExecExitCode"/>
</Exec>

Expand Down Expand Up @@ -657,7 +664,7 @@ For more information, see: https://github.com/ElectronNET/Electron.NET/wiki/Migr
<_NpxCmd Condition="'$(IsLinuxWsl)' == 'true'">wsl bash -ic '$(_NpxCmd)'</_NpxCmd>
</PropertyGroup>

<Exec Command="$(_NpxCmd)" WorkingDirectory="$(ElectronPublishDirFullPath)" Timeout="1800000" StandardOutputImportance="High" StandardErrorImportance="High" ContinueOnError="false" Condition="@(CopiedFiles->Count()) > 0">
<Exec Command="$(_NpxCmd)" WorkingDirectory="$(ElectronPublishDirFullPath)" Timeout="1800000" StandardOutputImportance="High" StandardErrorImportance="High" ContinueOnError="false" Condition="'$(ElectronSkipExecCommands)' != 'true' AND @(CopiedFiles->Count()) > 0">
<Output TaskParameter="ExitCode" PropertyName="ExecExitCode"/>
</Exec>

Expand Down
Loading