Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
[net8.0] fix C# compiler error involving x:Name (#242)
Browse files Browse the repository at this point in the history
Context: dotnet/maui#5611
Fixes: #239

The `net8.0` branch currently fails to build with:

    src/Mobile/Controls/Player.xaml.cs(54,9): error CS0103: The name 'podcastImage' does not exist in the current context
    src/Mobile/Controls/Player.xaml.cs(55,9): error CS0103: The name 'duration' does not exist in the current context

We think that `x:Name` in .NET 8 appropriately "skips" emitting fields
when used in combination with `<OnPlatform/>`.

We can condition the C# code accessing these fields with `#if`.

Secondly, there are also a lot places using `<On Platform="UWP, macOS">`, we need
to change these to:

* `macOS` -> `MacCatalyst`

Lastly, use .NET 8 RC 2 released bits. We shouldn't need to be using nightly builds in this repo.
  • Loading branch information
jonathanpeppers committed Oct 23, 2023
1 parent df5d09c commit 9cae3c9
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 21 deletions.
18 changes: 5 additions & 13 deletions .github/workflows/podcast-mobile.yml
Expand Up @@ -23,23 +23,15 @@ jobs:
- uses: actions/checkout@v2

- name: install .NET
shell: pwsh
run: |
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest https://dot.net/v1/dotnet-install.ps1 -OutFile dotnet-install.ps1
.\dotnet-install.ps1 -Channel 8.0 -Quality daily -InstallDir .
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x

- name: install MAUI workload
shell: pwsh
run: |
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest https://raw.githubusercontent.com/dotnet/maui/net8.0/NuGet.config -OutFile maui-main-NuGet.config
& .\dotnet workload install maui --from-rollback-file https://aka.ms/dotnet/maui/net8.0.json --configfile maui-main-NuGet.config
run: dotnet workload install maui

- name: build Microsoft.NetConf2021.Maui.csproj
shell: pwsh
run: |
& .\dotnet build src/Mobile/Microsoft.NetConf2021.Maui.csproj -bl:mobile.binlog
run: dotnet build src/Mobile/Microsoft.NetConf2021.Maui.csproj -bl:mobile.binlog

- name: archive logs
if: always()
Expand Down
6 changes: 3 additions & 3 deletions NuGet.config
Expand Up @@ -5,9 +5,9 @@
</fallbackPackageFolders>
<packageSources>
<clear />
<!-- Don't add nuget.org as a feed. If a new package is needed, it should be mirrored to the dotnet-public feed. -->
<add key="dotnet8" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json" />
<add key="dotnet-public" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" />
<!-- If a second feed is needed here, switch to dotnet-public feed. -->
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
<!-- <add key="dotnet-public" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" /> -->
</packageSources>
<disabledPackageSources>
<clear />
Expand Down
2 changes: 1 addition & 1 deletion src/Mobile/Controls/HeaderControl.xaml
Expand Up @@ -6,7 +6,7 @@
<ContentView.Content>
<ContentView>
<OnPlatform x:TypeArguments="View">
<On Platform="UWP, macOS">
<On Platform="UWP, MacCatalyst">
<Grid RowDefinitions="*, auto">
<SearchBar x:Name="searchBar"
HorizontalOptions="Start"
Expand Down
4 changes: 2 additions & 2 deletions src/Mobile/Controls/Player.xaml
Expand Up @@ -10,7 +10,7 @@
<ContentView.HeightRequest>
<OnPlatform x:TypeArguments="x:Double">
<On Platform="Android,iOS">70</On>
<On Platform="UWP,macOS">90</On>
<On Platform="UWP,MacCatalyst">90</On>
</OnPlatform>
</ContentView.HeightRequest>

Expand Down Expand Up @@ -42,7 +42,7 @@

</Grid>
</On>
<On Platform="UWP, macOS">
<On Platform="UWP, MacCatalyst">
<Grid ColumnDefinitions="auto, *, auto">
<Grid ColumnDefinitions="auto, auto"
RowDefinitions="auto,auto"
Expand Down
4 changes: 3 additions & 1 deletion src/Mobile/Controls/Player.xaml.cs
Expand Up @@ -46,13 +46,15 @@ private void UpdatePlayPause()
{
this.IsVisible = true;

#if ANDROID || IOS
this.playButton.Source = this.playerService.IsPlaying ? "player_pause.png" : "player_play.png";

epiosdeTitle.Text = this.playerService.CurrentEpisode.Title;
authorText.Text = $"{this.playerService.CurrentShow?.Author} - {this.playerService.CurrentEpisode?.Published.ToString("MMM, d yyy")}";

#else
podcastImage.Source = this.playerService.CurrentShow?.Image;
duration.Text = this.playerService.CurrentEpisode?.Duration.ToString();
#endif
}

private void PlayerService_IsPlayingChanged(object sender, EventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion src/Mobile/Pages/ShowDetailPage.xaml
Expand Up @@ -69,7 +69,7 @@
<ImageButton.IsVisible>
<OnPlatform x:TypeArguments="x:Boolean">
<On Platform="Android,iOS">false</On>
<On Platform="UWP,macOS">true</On>
<On Platform="UWP,MacCatalyst">true</On>
</OnPlatform>
</ImageButton.IsVisible>
<ImageButton.Triggers>
Expand Down

0 comments on commit 9cae3c9

Please sign in to comment.