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

Issues with AppHost generation with ArtifactsPath set #45926

Open
MaceWindu opened this issue Jan 13, 2025 · 0 comments
Open

Issues with AppHost generation with ArtifactsPath set #45926

MaceWindu opened this issue Jan 13, 2025 · 0 comments
Assignees
Labels
Area-NetSDK untriaged Request triage from a team member

Comments

@MaceWindu
Copy link

MaceWindu commented Jan 13, 2025

Describe the bug

We need to generate RID-specific apphost.exe files for our project, which we do using following post-build step in project file (see full example in attachment)

<Target Name="BuildAppHosts" AfterTargets="Build" Condition=" '$(RID)' == '' ">
    <ItemGroup>
      <TFM Include="$(TargetFrameworks)" Condition=" '$(TargetFramework)' == '' " Label="Build from VS" />
      <TFM Include="$(TargetFramework)" Condition=" '$(TargetFramework)' != '' " Label="Build from MSBUILD or dotnet" />
    </ItemGroup>

    <MSBuild Projects="$(MSBuildProjectFullPath)" Properties="RID=win-x86;Configuration=$(Configuration)" Targets="Build" />
    <Copy SourceFiles="<path to build results>\$(AssemblyName).exe" DestinationFiles="<path to main bin>\$(AssemblyName).win-x86.exe" />

    <MSBuild Projects="$(MSBuildProjectFullPath)" Properties="RID=win-x64;Configuration=$(Configuration)" Targets="Build" />
    <Copy SourceFiles="<path to build results>\$(AssemblyName).exe" DestinationFiles="<path to main bin>\$(AssemblyName).win-x64.exe" />
  </Target>

This works fine in default setup, but breaks when artifacts folder used.

First issue:
Now build with RID doesn't replace apphost.exe with one for current RID if file already exists. This could be workarounded by adding Delete file step, but then second issue arises.

Second issue:
If we delete apphost.exe on machine without SDK for target framework installed, it is not restored. E.g. we have net9.0 SDK and want to build for both net8.0 and net9.0 - it will fail with error like this:

##[error]C:\hostedtoolcache\windows\dotnet\sdk\9.0.101\Microsoft.Common.CurrentVersion.targets(5322,5): Error MSB3030: Could not copy the file "D:\a\1\s\.build\obj\LinqToDB.CLI\Azure\net6.0\apphost.exe" because it was not found.

Reason for that is failed condition evaluation for _CreateAppHost target because AppHostSourcePath property is empty:

https://github.com/dotnet/sdk/blob/v9.0.100/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets#L831

This property is empty, because it is initialized with ResolvedAppHostPack.Path property

https://github.com/dotnet/sdk/blob/v9.0.100/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets#L337

Which is empty if SDK is not installed (runtime-only install doesn't help)

There is PathInPackage property instead, which is not used by code above

2025-01-13T11:01:12.5598788Z                    Task "GetPackageDirectory" (TaskId:5097)
2025-01-13T11:01:12.5599161Z                      Task Parameter:
2025-01-13T11:01:12.5599500Z                          PackageFolders=
2025-01-13T11:01:12.5599841Z                              C:\Users\VssAdministrator\.nuget\packages\
2025-01-13T11:01:12.5600267Z                              C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages (TaskId:5097)
2025-01-13T11:01:12.5600672Z                      Task Parameter:
2025-01-13T11:01:12.5601014Z                          Items=
2025-01-13T11:01:12.5601318Z                              AppHost
2025-01-13T11:01:12.5601668Z                                      NuGetPackageId=Microsoft.NETCore.App.Host.win-x64
2025-01-13T11:01:12.5602096Z                                      NuGetPackageVersion=6.0.36
2025-01-13T11:01:12.5602552Z                                      PathInPackage=runtimes\win-x64\native\apphost.exe
2025-01-13T11:01:12.5602895Z                                      RuntimeIdentifier=win-x64 (TaskId:5097)
2025-01-13T11:01:12.5603234Z                      Output Item(s): 
2025-01-13T11:01:12.5603561Z                          ResolvedAppHostPack=
2025-01-13T11:01:12.5603815Z                              AppHost
2025-01-13T11:01:12.5604199Z                                      NuGetPackageId=Microsoft.NETCore.App.Host.win-x64
2025-01-13T11:01:12.5604630Z                                      NuGetPackageVersion=6.0.36
2025-01-13T11:01:12.5605074Z                                      OriginalItemSpec=AppHost
2025-01-13T11:01:12.5605676Z                                      PackageDirectory=C:\Users\VssAdministrator\.nuget\packages\microsoft.netcore.app.host.win-x64\6.0.36
2025-01-13T11:01:12.5606147Z                                      PathInPackage=runtimes\win-x64\native\apphost.exe
2025-01-13T11:01:12.5606549Z                                      RuntimeIdentifier=win-x64 (TaskId:5097)
2025-01-13T11:01:12.5606959Z                    Done executing task "GetPackageDirectory". (TaskId:5097)

https://github.com/dotnet/sdk/blob/v9.0.100/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets#L374

And yes, we cannot just install required SDKs as in that case we hit disk space limit during build on Azure DevOps...

To Reproduce

Test project. To switch between artifacts/non-artifacts build comment properties in Directory.Build.props

ResolvedAppHostPackBug.zip

Further technical details

  • Include the output of dotnet --info
.NET SDK:
 Version:           9.0.200-preview.0.24575.35
 Commit:            81b5f040be
 Workload version:  9.0.200-manifests.054dcb45
 MSBuild version:   17.13.0-preview-24569-04+8f6b8ad0a

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19045
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\9.0.200-preview.0.24575.35\

.NET workloads installed:
 [aspire]
   Installation Source: VS 17.12.35527.113
   Manifest Version:    8.2.2/8.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.2.2\WorkloadManifest.json
   Install Type:              Msi

Configured to use loose manifests when installing new manifests.

Host:
  Version:      9.0.0
  Architecture: x64
  Commit:       9d5a6a9aa4

.NET SDKs installed:
  3.1.426 [C:\Program Files\dotnet\sdk]
  6.0.315 [C:\Program Files\dotnet\sdk]
  9.0.101 [C:\Program Files\dotnet\sdk]
  9.0.200-preview.0.24575.35 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  arm64 [C:\Program Files\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\arm64\InstallLocation]
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-NetSDK untriaged Request triage from a team member labels Jan 13, 2025
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

2 participants