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

Build errors with multi-targeting Razor Class Library projects that include an MSBuild target depending on the CoreBuild target. (.NET SDK 9 Preview 7) #43120

Closed
jsakamoto opened this issue Aug 30, 2024 · 2 comments
Labels
Area-Workloads untriaged Request triage from a team member

Comments

@jsakamoto
Copy link

jsakamoto commented Aug 30, 2024

Describe the bug

I need to include the output files of my source generator to static web assets. So, I appended the following MSBuild target in the Blazor project files to follow @javiercn's advice.

  ...
  <Target Name="..."
    DependsOnTargets="CoreCompile"
    BeforeTargets="AssignTargetPaths;ResolveStaticWebAssetsConfiguration">
    <ItemGroup>
      <!-- Include a source generator's output files here. -->
    </ItemGroup>
  </Target>
  ...

(See also: jsakamoto/Toolbelt.Blazor.I18nText#63)

That worked fine for almost all kinds of Blazor projects. However, it failed with the following error messages when I tried to build a multi-targeting Razor Class Library project with the above MSBuild target, with the .NET SDK 9 Preview 7.

error CS0400: The type or namespace name 'System' could not be found in the global namespace (are you missing an assembly reference?)
error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)    
error CS0518: Predefined type 'System.String' is not defined or imported
...

Those errors were triggered when I just used the <TargetFrameworks> property in a Razor Class Library project file. It happened even when I specified only one target framework in that <TargetFrameworks> property, like below.

<Project Sdk="Microsoft.NET.Sdk.Razor">
  <PropertyGroup>
    <TargetFrameworks>net6.0</TargetFrameworks>
    ...

The build process succeeded when I rewrote the project file above to use the <TargetFramework> property. It also looks like there is no dependency on what the specified framework is. I've verified that this error happened on various of the "TargetFramworks" MSBuild property values, which are "net6.0", "net8.0", and "net9.0".

Again, the above MSBuild target worked fine on all kinds of projects, including multi-targeting projects, as long as they were Blazor Application projects, not Razor Class Library projects.

To Reproduce

Build the project I attached to this issue below with the .NET SDK 9 Preview 7. Then you will see the error messages I explained above.

📦Net9SWALib.zip

Exceptions (if any)

The build process must be successful.

Further technical details

The output of the dotnet --info

dotnet --info
.NET SDK:
 Version:           9.0.100-preview.7.24407.12
 Commit:            d672b8a045
 Workload version:  9.0.100-manifests.baed1e37
 MSBuild version:   17.12.0-preview-24374-02+48e81c6f1

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22631
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\9.0.100-preview.7.24407.12\

.NET workloads installed:
Configured to use loose manifests when installing new manifests.
 [android]
   Installation Source: SDK 9.0.100-preview.7, VS 17.12.35209.166, VS 17.11.35208.52
   Manifest Version:    35.0.0-preview.7.41/9.0.100-preview.7
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100-preview.7\microsoft.net.sdk.android\35.0.0-preview.7.41\WorkloadManifest.json
   Install Type:              Msi

 [aspire]
   Installation Source: SDK 9.0.100-preview.7, VS 17.11.35208.52
   Manifest Version:    8.1.0/8.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.1.0\WorkloadManifest.json
   Install Type:        FileBased

 [ios]
   Installation Source: SDK 9.0.100-preview.7, VS 17.12.35209.166, VS 17.11.35208.52
   Manifest Version:    17.5.9231-net9-p7/9.0.100-preview.7
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100-preview.7\microsoft.net.sdk.ios\17.5.9231-net9-p7\WorkloadManifest.json
   Install Type:              Msi

 [maccatalyst]
   Installation Source: SDK 9.0.100-preview.7, VS 17.12.35209.166, VS 17.11.35208.52
   Manifest Version:    17.5.9231-net9-p7/9.0.100-preview.7
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100-preview.7\microsoft.net.sdk.maccatalyst\17.5.9231-net9-p7\WorkloadManifest.json
   Install Type:              Msi

 [maui-windows]
   Installation Source: SDK 9.0.100-preview.7, VS 17.12.35209.166, VS 17.11.35208.52
   Manifest Version:    9.0.0-preview.7.24407.4/9.0.100-preview.7
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100-preview.7\microsoft.net.sdk.maui\9.0.0-preview.7.24407.4\WorkloadManifest.json
   Install Type:              Msi

 [wasm-tools]
   Installation Source: SDK 9.0.100-preview.7, VS 17.12.35209.166
   Manifest Version:    9.0.0-preview.7.24405.7/9.0.100-preview.7
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100-preview.7\microsoft.net.workload.mono.toolchain.current\9.0.0-preview.7.24405.7\WorkloadManifest.json
   Install Type:              Msi

 [wasm-tools-net6]
   Installation Source: SDK 9.0.100-preview.7, VS 17.12.35209.166
   Manifest Version:    9.0.0-preview.7.24405.7/9.0.100-preview.7
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100-preview.7\microsoft.net.workload.mono.toolchain.net6\9.0.0-preview.7.24405.7\WorkloadManifest.json
   Install Type:              Msi

 [wasm-tools-net7]
   Installation Source: SDK 9.0.100-preview.7, VS 17.12.35209.166
   Manifest Version:    9.0.0-preview.7.24405.7/9.0.100-preview.7
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100-preview.7\microsoft.net.workload.mono.toolchain.net7\9.0.0-preview.7.24405.7\WorkloadManifest.json
   Install Type:              Msi

 [wasm-tools-net8]
   Installation Source: SDK 9.0.100-preview.7
   Manifest Version:    9.0.0-preview.7.24405.7/9.0.100-preview.7
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100-preview.7\microsoft.net.workload.mono.toolchain.net8\9.0.0-preview.7.24405.7\WorkloadManifest.json
   Install Type:              Msi


Host:
  Version:      9.0.0-preview.7.24405.7
  Architecture: x64
  Commit:       static

.NET SDKs installed:
  3.1.426 [C:\Program Files\dotnet\sdk]
  5.0.408 [C:\Program Files\dotnet\sdk]
  6.0.425 [C:\Program Files\dotnet\sdk]
  7.0.410 [C:\Program Files\dotnet\sdk]
  8.0.400 [C:\Program Files\dotnet\sdk]
  9.0.100-preview.7.24407.12 [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.33 [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.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.0-preview.7.24406.2 [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.33 [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.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.0-preview.7.24405.7 [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.33 [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.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.0-preview.7.24405.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

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

Environment variables:
  Not set

global.json file:
  C:\Projects\Feedbacks\Blazor\Net9andStaticWebAssets\RCL\global.json

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

Download .NET:
  https://aka.ms/dotnet/download

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Workloads untriaged Request triage from a team member labels Aug 30, 2024
@jsakamoto jsakamoto changed the title Build errors with multi-targeting Razor Class Library projects that include an MSBuild target depending on the CoreBuild target. Build errors with multi-targeting Razor Class Library projects that include an MSBuild target depending on the CoreBuild target. (.NET SDK 9 Preview 7) Aug 30, 2024
@javiercn
Copy link
Member

javiercn commented Sep 3, 2024

@jsakamoto thanks for contacting us.

Change the target for ResolveProjectStaticWebAssets. See if that helps.

  <Target Name="IncludeStaticWebAssetsNet9"
    DependsOnTargets="CoreCompile"
    BeforeTargets="ResolveProjectStaticWebAssets"
    Condition="$([MSBuild]::VersionGreaterThanOrEquals('$(NETCoreSdkVersion)', '9.0'))">
    <ItemGroup>
      <!-- TODO -->
    </ItemGroup>
  </Target>

@jsakamoto
Copy link
Author

I verified your advice about changing the BeforeTargets parameter, and it worked!
Thank you, @javiercn, for your prompt response!

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

No branches or pull requests

2 participants