Skip to content

Commit

Permalink
fix: Adjust target framework order for window
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Apr 4, 2024
1 parent c8e22c5 commit 9b60e26
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
18 changes: 16 additions & 2 deletions doc/articles/uno-build-error-codes.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Alternatively you may disable the Implicit Package References

### UNOB00010: The browserwasm TargetFramework must not be placed first in the TargetFrameworks property

In Visual Studio 2022, an issue prevents debugging and Hot Reload from working properly for all targets when the `net8.0-browserwasm` TargetFramework is placed first in the `TargetFrameworks` property.
In Visual Studio 2022, [an issue](https://aka.platform.uno/singleproject-vs-reload) prevents debugging and Hot Reload from working properly for all targets when the `net8.0-browserwasm` TargetFramework is placed first in the `TargetFrameworks` property.

Make sure to place `net8.0-browserwasm` last in your `<TargetFrameworks>` property.

Expand All @@ -83,7 +83,7 @@ This warning can be disabled by adding the following to your `.csproj`:

### UNOB00011: The desktop TargetFramework must not be placed first in the TargetFrameworks property

In Visual Studio 2022, an issue prevents other platforms debugging from working properly when the `net8.0-desktop` TargetFramework is placed first in the `TargetFrameworks` property.
In Visual Studio 2022, [an issue](https://aka.platform.uno/singleproject-vs-reload) prevents other platforms debugging from working properly when the `net8.0-desktop` TargetFramework is placed first in the `TargetFrameworks` property.

Make sure that `net8.0-desktop` is not first in your `<TargetFrameworks>` property.

Expand All @@ -95,6 +95,20 @@ This warning can be disabled by adding the following to your `.csproj`:
</PropertyGroup>
```

### UNOB00012: The windows TargetFramework must not be placed first in the TargetFrameworks property

In Visual Studio 2022, [an issue](https://aka.platform.uno/singleproject-vs-reload) prevents other platforms debugging from working properly when the `net8.0-windows10.xxx` TargetFramework is placed first in the `TargetFrameworks` property.

Make sure that `net8.0-windows10.xxx` is not first in your `<TargetFrameworks>` property.

This warning can be disabled by adding the following to your `.csproj`:

```xml
<PropertyGroup>
<UnoDisableVSWarnWindowsIsFirst>true</UnoDisableVSWarnWindowsIsFirst>
</PropertyGroup>
```

## Compiler Errors

### UNO0001
Expand Down
17 changes: 15 additions & 2 deletions src/Uno.Sdk/targets/Uno.Sdk.After.targets
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
</ItemGroup>

<!--
Adjust the first target framework to be browserwasm or desktop, if the current debugging
target is browserwasm. This portion is linked to the TryReloadWebAssemblyOrDesktopTargetAsync in
Adjust the first target framework to be browserwasm or desktop or windows, if the current debugging
target is either of those. This portion is linked to the TryReloadTargetAsync in
the Uno.UI.RemoteControl.VS project.
This is required by a WebAssembly/Desktop support issue in VS, where both Publishing/Debugging and other
Expand All @@ -31,6 +31,7 @@
(
$([MSBuild]::GetTargetPlatformIdentifier($(ActiveDebugFramework))) == 'browserwasm'
OR $([MSBuild]::GetTargetPlatformIdentifier($(ActiveDebugFramework))) == 'desktop'
OR $([MSBuild]::GetTargetPlatformIdentifier($(ActiveDebugFramework))) == 'windows'
)
AND '$(TargetFrameworks)' != ''
AND !$(TargetFrameworks.StartsWith($(ActiveDebugFramework)))
Expand Down Expand Up @@ -67,6 +68,18 @@
Text="The desktop TargetFramework must not be placed first in the TargetFrameworks property in order for other platforms debugging to work. (See https://aka.platform.uno/UNOB0011)" />
</Target>

<Target Name="_UnoVSWarnWindowsIsFirst"
BeforeTargets="_SetBuildInnerTarget;_ComputeTargetFrameworkItems"
Condition="
'$(UnoDisableVSWarnWindowsIsFirst)' != 'true'
AND '$(BuildingInsideVisualStudio)' == 'true'
AND '$(_UnoTargetFrameworkCount)' != ''
AND $(_UnoTargetFrameworkCount) &gt; 1
AND $([MSBuild]::GetTargetPlatformIdentifier($(_UnoFirstOriginalTargetFramework))) == 'windows'">

<Warning Code="UNOB0012"
Text="The windows TargetFramework must not be placed first in the TargetFrameworks property in order for other platforms debugging to work. (See https://aka.platform.uno/UNOB0012)" />
</Target>

<!-- Include any additional targets that packages defined by other packages -->
<Import Project="$(AfterUnoSdkTargets)" Condition="'$(AfterUnoSdkTargets)' != ''"/>
Expand Down
10 changes: 5 additions & 5 deletions src/Uno.UI.RemoteControl.VS/EntryPoint.ActiveProfileSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ bool IsCompatible(ILaunchProfile profile)
}
}

await TryReloadWebAssemblyOrDesktopTargetAsync(previousFramework, newFramework, targetFrameworkIdentifier);
await TryReloadTargetAsync(previousFramework, newFramework, targetFrameworkIdentifier);
}
}

Expand Down Expand Up @@ -146,7 +146,7 @@ private async Task OnDebugProfileChangedAsync(string? previousProfile, string ne
=> targetFrameworks.FirstOrDefault(f => f.IndexOf("-" + identifier, StringComparison.OrdinalIgnoreCase) != -1);
}

private async Task TryReloadWebAssemblyOrDesktopTargetAsync(string? previousFramework, string newFramework, string targetFrameworkIdentifier)
private async Task TryReloadTargetAsync(string? previousFramework, string newFramework, string targetFrameworkIdentifier)
{
if (_wasmProjectReloadTask is not null)
{
Expand All @@ -160,8 +160,8 @@ private async Task TryReloadWebAssemblyOrDesktopTargetAsync(string? previousFram
if (previousFramework is not null
&& GetTargetFrameworkIdentifier(previousFramework) is { } previousTargetFrameworkIdentifier
&& (
previousTargetFrameworkIdentifier is WasmTargetFrameworkIdentifier or DesktopTargetFrameworkIdentifier
|| targetFrameworkIdentifier is WasmTargetFrameworkIdentifier or DesktopTargetFrameworkIdentifier)
previousTargetFrameworkIdentifier is WasmTargetFrameworkIdentifier or DesktopTargetFrameworkIdentifier or Windows10TargetFrameworkIdentifier
|| targetFrameworkIdentifier is WasmTargetFrameworkIdentifier or DesktopTargetFrameworkIdentifier or Windows10TargetFrameworkIdentifier)
&& await _dte.GetStartupProjectsAsync() is { Length: > 0 } startupProjects
)
{
Expand Down Expand Up @@ -192,7 +192,7 @@ previousTargetFrameworkIdentifier is WasmTargetFrameworkIdentifier or DesktopTar
return;
}

_warningAction?.Invoke($"Detected that the active framework was changed from/to WebAssembly/Desktop, reloading the project (See https://aka.platform.uno/singleproject-vs-reload)");
_warningAction?.Invoke($"Detected that the active framework was changed from/to WebAssembly/Desktop/Windows, reloading the project (See https://aka.platform.uno/singleproject-vs-reload)");

// In this context, in order to work around the fact that VS does not handle Wasm
// to be in the same project as other target framework, we're using the `_SelectedTargetFramework`
Expand Down

0 comments on commit 9b60e26

Please sign in to comment.