|
297 | 297 | <RemoveDir Directories="$(ElectronHookTargetModuleDir)" Condition="Exists($(ElectronHookTargetModuleDir))" /> |
298 | 298 | </Target> |
299 | 299 |
|
| 300 | + <Target Name="ElectronCheckVersionMismatch"> |
| 301 | + |
| 302 | + <PropertyGroup> |
| 303 | + <ElectronArch Condition="'$(RuntimeIdentifier)' == 'win-x64'">x64</ElectronArch> |
| 304 | + <ElectronArch Condition="'$(RuntimeIdentifier)' == 'win-x86'">ia32</ElectronArch> |
| 305 | + <ElectronArch Condition="'$(RuntimeIdentifier)' == 'win-arm64'">arm64</ElectronArch> |
| 306 | + <ElectronArch Condition="'$(RuntimeIdentifier)' == 'linux-x64'">x64</ElectronArch> |
| 307 | + <ElectronArch Condition="'$(RuntimeIdentifier)' == 'linux-arm'">armv7l</ElectronArch> |
| 308 | + <ElectronArch Condition="'$(RuntimeIdentifier)' == 'linux-arm64'">arm64</ElectronArch> |
| 309 | + <ElectronArch Condition="'$(RuntimeIdentifier)' == 'osx-x64'">x64</ElectronArch> |
| 310 | + <ElectronArch Condition="'$(RuntimeIdentifier)' == 'osx-arm64'">arm64</ElectronArch> |
| 311 | + |
| 312 | + <ElectronPlatform Condition="'$(RuntimeIdentifier)' == 'win-x64' OR '$(RuntimeIdentifier)' == 'win-x86' OR '$(RuntimeIdentifier)' == 'win-arm64'">win</ElectronPlatform> |
| 313 | + <ElectronPlatform Condition="'$(RuntimeIdentifier)' == 'linux-x64' OR '$(RuntimeIdentifier)' == 'linux-arm' OR '$(RuntimeIdentifier)' == 'linux-arm64'">linux</ElectronPlatform> |
| 314 | + <ElectronPlatform Condition="'$(RuntimeIdentifier)' == 'osx-x64' OR '$(RuntimeIdentifier)' == 'osx-arm64'">mac</ElectronPlatform> |
| 315 | + |
| 316 | + <!-- npm uses different OS names than Electron --> |
| 317 | + <NpmOs Condition="'$(ElectronPlatform)' == 'win'">win32</NpmOs> |
| 318 | + <NpmOs Condition="'$(ElectronPlatform)' == 'linux'">linux</NpmOs> |
| 319 | + <NpmOs Condition="'$(ElectronPlatform)' == 'mac'">darwin</NpmOs> |
| 320 | + |
| 321 | + <!-- npm CPU is same as ElectronArch except for linux-arm --> |
| 322 | + <NpmCpu>$(ElectronArch)</NpmCpu> |
| 323 | + <NpmCpu Condition="'$(RuntimeIdentifier)' == 'linux-arm'">arm</NpmCpu> |
| 324 | + |
| 325 | + <_CurrentOSPlatform Condition="$([MSBuild]::IsOSPlatform('Windows'))">win</_CurrentOSPlatform> |
| 326 | + <_CurrentOSPlatform Condition="$([MSBuild]::IsOSPlatform('Linux'))">linux</_CurrentOSPlatform> |
| 327 | + <_CurrentOSPlatform Condition="$([MSBuild]::IsOSPlatform('OSX'))">mac</_CurrentOSPlatform> |
| 328 | + </PropertyGroup> |
| 329 | + |
| 330 | + <!-- Validate that the target platform matches the current OS --> |
| 331 | + <PropertyGroup> |
| 332 | + <IsLinuxWsl>false</IsLinuxWsl> |
| 333 | + <IsLinuxWsl Condition="'$(ElectronPlatform)' == 'linux' AND '$(_CurrentOSPlatform)' == 'win'">true</IsLinuxWsl> |
| 334 | + |
| 335 | + <_IsCrossCompileAllowed>false</_IsCrossCompileAllowed> |
| 336 | + <!-- Allow Linux builds on Windows via WSL --> |
| 337 | + <_IsCrossCompileAllowed Condition="'$(_CurrentOSPlatform)' == 'win' AND '$(ElectronPlatform)' == 'linux' AND '$(IsLinuxWsl)' == 'true'">true</_IsCrossCompileAllowed> |
| 338 | + |
| 339 | + <_IsPlatformMismatch>false</_IsPlatformMismatch> |
| 340 | + <_IsPlatformMismatch Condition="'$(_CurrentOSPlatform)' != '$(ElectronPlatform)' AND '$(_IsCrossCompileAllowed)' != 'true'">true</_IsPlatformMismatch> |
| 341 | + |
| 342 | + </PropertyGroup> |
| 343 | + |
| 344 | + </Target> |
| 345 | + |
300 | 346 |
|
301 | 347 | <Target Name="ElectronConfigureApp" |
302 | 348 | Inputs="@(ElectronPackageJsonFiles)" |
303 | 349 | Outputs="@(ElectronPackageJsonFiles->'$(OutDir)%(TargetPath)')" |
304 | 350 | AfterTargets="CopyFilesToOutputDirectory" |
305 | | - DependsOnTargets="ElectronResetHostHook" |
| 351 | + DependsOnTargets="ElectronResetHostHook;ElectronCheckVersionMismatch" |
306 | 352 | > |
307 | 353 |
|
308 | 354 | <Copy SourceFiles="@(ElectronPackageJsonFiles)" DestinationFiles="@(ElectronPackageJsonFiles->'$(OutDir)%(TargetPath)')" > |
|
316 | 362 |
|
317 | 363 | <PropertyGroup> |
318 | 364 | <ElectronOutputPath>$([System.IO.Path]::GetFullPath('$(ElectronOutDir)'))</ElectronOutputPath> |
319 | | - <LinuxPrefix>linux</LinuxPrefix> |
320 | | - <IsLinuxWsl>false</IsLinuxWsl> |
321 | | - <IsLinuxWsl Condition="'$(RuntimeIdentifier.StartsWith($(LinuxPrefix)))' == 'true'AND $([MSBuild]::IsOSPlatform('Windows'))">true</IsLinuxWsl> |
322 | 365 | <_NpmCmd>npm install --no-bin-links</_NpmCmd> |
| 366 | + <!-- Add cross-platform parameters when there's a platform mismatch (for remote debugging preparation) --> |
| 367 | + <_NpmCmd Condition="'$(_IsPlatformMismatch)' == 'true'">$(_NpmCmd) --os=$(NpmOs) --cpu=$(NpmCpu) --arch=$(NpmCpu) --platform=$(NpmOs)</_NpmCmd> |
323 | 368 | <_NpmCmd Condition="'$(IsLinuxWsl)' == 'true'">wsl bash -ic '$(_NpmCmd)'</_NpmCmd> |
324 | 369 | </PropertyGroup> |
325 | 370 |
|
|
335 | 380 |
|
336 | 381 | <Message Importance="High" Text="Electron setup failed!" Condition="'$(ExecExitCode)' != '0'" /> |
337 | 382 |
|
| 383 | + <!-- Fix up incorrect symlinks created by npm on Windows when targeting macOS --> |
| 384 | + <PropertyGroup> |
| 385 | + <_ElectronFrameworksDir>$(ElectronOutDir)node_modules\electron\dist\Electron.app\Contents\Frameworks</_ElectronFrameworksDir> |
| 386 | + </PropertyGroup> |
| 387 | + |
| 388 | + <ItemGroup> |
| 389 | + <_ElectronFrameworkDirs Include="$(_ElectronFrameworksDir)\Electron Framework.framework" /> |
| 390 | + <_ElectronFrameworkDirs Include="$(_ElectronFrameworksDir)\Mantle.framework" /> |
| 391 | + <_ElectronFrameworkDirs Include="$(_ElectronFrameworksDir)\ReactiveObjC.framework" /> |
| 392 | + <_ElectronFrameworkDirs Include="$(_ElectronFrameworksDir)\Squirrel.framework" /> |
| 393 | + </ItemGroup> |
| 394 | + |
| 395 | + <!-- Only execute on Windows host when targeting macOS --> |
| 396 | + <Message Importance="High" Text="Fixing macOS framework Resources symlinks" Condition="'$(ElectronPlatform)' == 'mac' AND '$(_CurrentOSPlatform)' == 'win'" /> |
| 397 | + |
| 398 | + <Exec Command="cmd /c del Resources && mklink /D Resources "Versions\Current\Resources"" WorkingDirectory="%(_ElectronFrameworkDirs.Identity)" Condition="'$(ElectronPlatform)' == 'mac' AND '$(_CurrentOSPlatform)' == 'win'" /> |
| 399 | + |
338 | 400 | </Target> |
339 | 401 |
|
340 | 402 | <Target Name="BeforePublishElectronApp" BeforeTargets="PrepareForPublish"> |
|
367 | 429 | <_ElectronPublishAppAfterTarget Condition="'$(UsingMicrosoftNETSdkWeb)' != 'true'">Publish</_ElectronPublishAppAfterTarget> |
368 | 430 | </PropertyGroup> |
369 | 431 |
|
370 | | - <Target Name="ElectronPublishApp" AfterTargets="$(_ElectronPublishAppAfterTarget)"> |
| 432 | + <Target Name="ElectronPublishApp" AfterTargets="$(_ElectronPublishAppAfterTarget)" DependsOnTargets="ElectronCheckVersionMismatch"> |
371 | 433 |
|
372 | 434 | <PropertyGroup> |
373 | 435 | <PublishDir>$(_OriginalPublishDir)</PublishDir> |
|
376 | 438 | </PropertyGroup> |
377 | 439 |
|
378 | 440 |
|
379 | | - <PropertyGroup> |
380 | | - <!-- Default values --> |
381 | | - <ElectronArch Condition="'$(RuntimeIdentifier)' == 'win-x64'">x64</ElectronArch> |
382 | | - <ElectronArch Condition="'$(RuntimeIdentifier)' == 'win-x86'">ia32</ElectronArch> |
383 | | - <ElectronArch Condition="'$(RuntimeIdentifier)' == 'win-arm64'">arm64</ElectronArch> |
384 | | - <ElectronArch Condition="'$(RuntimeIdentifier)' == 'linux-x64'">x64</ElectronArch> |
385 | | - <ElectronArch Condition="'$(RuntimeIdentifier)' == 'linux-arm'">armv7l</ElectronArch> |
386 | | - <ElectronArch Condition="'$(RuntimeIdentifier)' == 'linux-arm64'">arm64</ElectronArch> |
387 | | - <ElectronArch Condition="'$(RuntimeIdentifier)' == 'osx-x64'">x64</ElectronArch> |
388 | | - <ElectronArch Condition="'$(RuntimeIdentifier)' == 'osx-arm64'">arm64</ElectronArch> |
| 441 | + <Error Condition="'$(_IsPlatformMismatch)' == 'true'" |
| 442 | + Code="ELECTRON100" |
| 443 | + Text="The target RuntimeIdentifier '$(RuntimeIdentifier)' (platform: $(ElectronPlatform)) does not match the current operating system ($(_CurrentOSPlatform)). |
389 | 444 |
|
390 | | - <ElectronPlatform Condition="'$(RuntimeIdentifier)' == 'win-x64' OR '$(RuntimeIdentifier)' == 'win-x86' OR '$(RuntimeIdentifier)' == 'win-arm64'">win</ElectronPlatform> |
391 | | - <ElectronPlatform Condition="'$(RuntimeIdentifier)' == 'linux-x64' OR '$(RuntimeIdentifier)' == 'linux-arm' OR '$(RuntimeIdentifier)' == 'linux-arm64'">linux</ElectronPlatform> |
392 | | - <ElectronPlatform Condition="'$(RuntimeIdentifier)' == 'osx-x64' OR '$(RuntimeIdentifier)' == 'osx-arm64'">mac</ElectronPlatform> |
393 | | - </PropertyGroup> |
| 445 | +Electron applications must be built on the target operating system: |
| 446 | +- Windows targets (win-x64, win-x86, win-arm64) must be built on Windows |
| 447 | +- Linux targets (linux-x64, linux-arm, linux-arm64) must be built on Linux (or Windows with WSL) |
| 448 | +- macOS targets (osx-x64, osx-arm64) must be built on macOS |
| 449 | +
|
| 450 | +EXCEPTION: Linux targets can be built on Windows using WSL (Windows Subsystem for Linux). |
| 451 | +
|
| 452 | +For more information, see: https://github.com/ElectronNET/Electron.NET/wiki/Migration-Checks#8-cross-platform-build-validation" /> |
394 | 453 |
|
395 | 454 | <RemoveEnvironmentVariables Variables="BUILD_BUILDNUMBER;BUILD_NUMBER;TRAVIS_BUILD_NUMBER;APPVEYOR_BUILD_NUMBER;CIRCLE_BUILD_NUM;CI_PIPELINE_IID" /> |
396 | 455 |
|
|
0 commit comments