Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ApplicationManifest is not respected when building for Windows on Linux #23627

Closed
LordMike opened this issue Jan 27, 2022 · 14 comments
Closed

ApplicationManifest is not respected when building for Windows on Linux #23627

LordMike opened this issue Jan 27, 2022 · 14 comments
Assignees
Labels
Area-NetSDK untriaged Request triage from a team member

Comments

@LordMike
Copy link
Contributor

Describe the bug

We want to create a Windows .EXE from our application, in our Linux build chain. We can sucessfully create and run the exectuable on windows, but it comes without the manifest we put in the ApplicationManifest property in our csproj file.

When building on Windows, the manifest is embedded correctly.

To Reproduce

Create a manifest file to embed, like MyApp.manifest:

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <assemblyIdentity type="win32" version="1.0.0.0" name="MyApp" />
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
      </requestedPrivileges>
    </security>
  </trustInfo>
  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
      <!--Windows Vista -->
      <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
      <!--Windows 7 -->
      <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
      <!--Windows 8 -->
      <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
      <!--Windows 8.1 -->
      <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
      <!--Windows 10 -->
      <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
    </application>
  </compatibility>
</asmv1:assembly>

In a new console app, add the ApplicationManifest to a PropertyGroup:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>

  <PropertyGroup>
    <ApplicationManifest>MyApp.manifest</ApplicationManifest>
  </PropertyGroup>

   ....
</Project>

Build it on Windows:

dotnet build -r win-x64 --self-contained -o Build

# Observe that the Exe file in Build has a manifest (a Shield in Windows Explorer to indicate it requires admin)

Build it in Linux (f.ex. the Dotnet 6 SDK docker images):

# Startup a docker container with SDK 6
docker run -it --rm -v $pwd`:/app mcr.microsoft.com/dotnet/sdk:6.0

# Build within Docker
cd /app
dotnet build -r win-x64 --self-contained -o Build

# Back in Windows, observe that the Exe file in Build is lacking a manifest

Exceptions (if any)

N/A

Further technical details

Windows

> dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.101
 Commit:    ef49f6213a

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19043
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\6.0.101\

Host (useful for support):
  Version: 6.0.1
  Commit:  3a25a7f1cc

.NET SDKs installed:
  3.1.416 [C:\Program Files\dotnet\sdk]
  5.0.404 [C:\Program Files\dotnet\sdk]
  6.0.101 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

Docker (Linux)

$ dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.101
 Commit:    ef49f6213a

Runtime Environment:
 OS Name:     debian
 OS Version:  11
 OS Platform: Linux
 RID:         debian.11-x64
 Base Path:   /usr/share/dotnet/sdk/6.0.101/

Host (useful for support):
  Version: 6.0.1
  Commit:  3a25a7f1cc

.NET SDKs installed:
  6.0.101 [/usr/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.1 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-NetSDK untriaged Request triage from a team member labels Jan 27, 2022
@KalleOlaviNiemitalo
Copy link

This seems a duplicate of dotnet/runtime#3828. The Roslyn compiler embeds the manifest as a Win32 resource to the DLL all right, but a separate tool is supposed to copy the Win32 resources to the apphost EXE, and that part still uses the Windows API so cannot work on Linux. ResourceUpdater.IsSupportedOS(), CreateAppHost.ExecuteCore()

@KalleOlaviNiemitalo
Copy link

If it had been a GUI app, then you'd have got warning NETSDK1074. But there's no warning about losing resources of a console app in a similar way.

@LordMike
Copy link
Contributor Author

Oh dammit ... :/

@marcpopMSFT
Copy link
Member

@vitek-karas @agocke this looks like an longstanding issue in the host model code. Is that something ya'll are considering looking into?

@agocke
Copy link
Member

agocke commented Feb 9, 2022

Looks like a dupe of dotnet/runtime#3828. Have not scheduled it for a release yet.

@LordMike
Copy link
Contributor Author

Adding to the severity is that I couldn't make mt.exe work for us, embedding the manifest after the build. It simply truncates the .exe file and removes what seems to be our .NET application.

@MaverickMartyn
Copy link

Just chiming in here to voice my need for this feature as well.
Build server runs linux and I have WPF .NET 6 apps for Windows only that I'd like to integrate in my CI pipeline.
This means I'm stuck on .NET 4.8 and miss out on the newer .NET and C# features.
Is there any ETA at this time, or a decent workaround? :)

@jackmtpt
Copy link

Any update on this?

@agocke
Copy link
Member

agocke commented Feb 13, 2023

This has not been implemented yet -- the recommendation is still to build your Windows build on Windows in CI.

There's no functionality difference here for Core vs Desktop, it's just a requirement that you build on Windows when creating a Windows GUI app.

@jackmtpt
Copy link

Is it planned for any future release? To be clear, this is a console app rather than GUI (which of course would have to be built on windows) and since we're building all the other parts of this solution on linux it would be much simpler if we didn't need windows just to embed the manifest into the final exe.

@agocke
Copy link
Member

agocke commented Feb 14, 2023

Definitely something we would like to implement, it just hasn't yet raised in priority enough to beat out a variety of other bug fixes and features. We would accept a community PR if someone wants to offer one.

@MaverickMartyn
Copy link

Is it planned for any future release? To be clear, this is a console app rather than GUI (which of course would have to be built on windows) and since we're building all the other parts of this solution on linux it would be much simpler if we didn't need windows just to embed the manifest into the final exe.

Just to be clear, there is no real reason why we couldn't build Windows GUI apps on linux. It's just the manifest that is broken, even for GUI apps.

@KalleOlaviNiemitalo
Copy link

dotnet/runtime#3828 has been fixed. According to dotnet/runtime#3828 (comment), the fix will be in .NET 8.

@Genbox
Copy link

Genbox commented Nov 14, 2023

Just tested this on .NET 8. It does indeed support embedding application manifests on Linux. The issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-NetSDK untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

8 participants