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

[workload] move all build tasks out of library-packs #4235

Merged
merged 1 commit into from
Jan 21, 2022

Conversation

jonathanpeppers
Copy link
Member

Description of Change

Fixes: https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1459138
Fixes: #4098

This partially reverts 974cac4.

Creating a new MAUI solution, results in several intellisense errors:

CS0103: The name 'InitializeComponent` does not exist in the current context.

The missing members are created by the (previously XamlG) Roslyn
source generator. You can go-to definition the missing members, build
& run works, and if you close/reopen the solution the errors go away.
Unchecking the Run code analysis in a separate process, also seems
to solve the issue.

.NET MAUI seems to be using an intersection of features that causes
this problem:

  1. We have a dotnet new maui project template.
  2. We have a source generator in a NuGet package.
  3. We have MSBuild targets that setup the source generator in a NuGet
    package.
  4. We use AdditionalFiles to pass .xaml files in to the source
    generator.

What happens on the first project load, the design-time builds
before project restore are missing the source generator. So the call
to <Csc/> does not have @(Analyzer) or AdditionalFiles at all.

To solve this issue, we can move everything out of NuGet packages,
so they become regular "SDK" or workload packs:

  • Microsoft.Maui.Controls.Build.Tasks is no longer packable
    • all files moved to Microsoft.Maui.Sdk
  • Resizetizer.csproj is no longer packable
    • actual files are in Microsoft.Maui.Resizetizer.Sdk
  • $(MauiVersion) no longer applies to build tasks

Testing locally, this seems to solve the problem for me. I can see the
@(Analyzer) and AdditionalFiles being passed on all design-time
builds now.

Other changes:

  • I added %(IsImplicitlyDefined) to the source generator assembly. I
    just noticed this was missing while reading .binlog files.
  • I put all files in the Sdk folder in Microsoft.Maui.Sdk. This
    seems a bit simpler to have one directory.

PR Checklist

  • Targets the correct branch
  • Tests are passing (or failures are unrelated)
  • Targets a single property for a single control (or intertwined few properties)
  • Adds the property to the appropriate interface
  • Avoids any changes not essential to the handler property
  • Adds the mapping to the PropertyMapper in the handler
  • Adds the mapping method to the WinUI, Android, iOS, and Standard aspects of the handler
  • Implements the actual property updates (usually in extension methods in the Platform section of Core)
  • Tags ported renderer methods with [PortHandler]
  • Adds an example of the property to the sample project (MainPage)
  • Adds the property to the stub class
  • Implements basic property tests in DeviceTests

Does this PR touch anything that might affect accessibility?

No

@jonathanpeppers jonathanpeppers force-pushed the no-build-tasks-in-library-packs branch 3 times, most recently from b50f2b6 to cc59925 Compare January 20, 2022 19:58
@jonathanpeppers
Copy link
Member Author

So I went through the nightmare of installing the packs from CI:

  1. I started with 17.1 Preview 3, the MAUI workload from VS.
  2. Delete C:\Program Files\dotnet\metadata\workloads\6.0.200\installertype\msi
  3. signtool remove /s "C:\Program Files\dotnet\sdk\6.0.200-preview.22055.15\dotnet.dll"
  4. Download the nuget artifact and put all *.nupkg files in C:\src\maui\artifacts
  5. Install workloads from maui/main: dotnet workload install maui --from-rollback-file https://aka.ms/dotnet/maui/main.json --source https://aka.ms/dotnet6/nuget/index.json --source https://api.nuget.org/v3/index.json
  6. Install the local .nupkg files on top: dotnet build src/DotNet/DotNet.csproj -t:Install

It works!

image

Fixes: https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1459138
Fixes: dotnet#4098

This partially reverts 974cac4.

Creating a new MAUI solution, results in several intellisense errors:

    CS0103: The name 'InitializeComponent` does not exist in the current context.

The missing members are created by the (previously XamlG) Roslyn
source generator. You can go-to definition the missing members, build
& run works, and if you close/reopen the solution the errors go away.
Unchecking the `Run code analysis in a separate process`, also seems
to solve the issue.

.NET MAUI seems to be using an intersection of features that causes
this problem:

1. We have a `dotnet new maui` project template.
2. We have a source generator in a NuGet package.
3. We have MSBuild targets that setup the source generator in a NuGet
   package.
4. We use `AdditionalFiles` to pass `.xaml` files in to the source
   generator.

What happens on the first project load, the design-time builds
*before* project restore are missing the source generator. So the call
to `<Csc/>` does not have `@(Analyzer)` or `AdditionalFiles` at all.

To solve this issue, we can move everything *out* of NuGet packages,
so they become regular "SDK" or workload packs:

* `Microsoft.Maui.Controls.Build.Tasks` is no longer packable
    * all files moved to `Microsoft.Maui.Sdk`
* `Resizetizer.csproj` is no longer packable
    * actual files are in `Microsoft.Maui.Resizetizer.Sdk`
* `$(MauiVersion)` no longer applies to build tasks

Testing locally, this seems to solve the problem for me. I can see the
`@(Analyzer)` and `AdditionalFiles` being passed on all design-time
builds now.

Other changes:

* I added `%(IsImplicitlyDefined)` to the source generator assembly. I
  just noticed this was missing while reading `.binlog` files.
* I put all files in the `Sdk` folder in `Microsoft.Maui.Sdk`. This
  seems a bit simpler to have one directory.
@jonathanpeppers jonathanpeppers marked this pull request as ready for review January 21, 2022 03:16
@Redth Redth merged commit 1bc403e into dotnet:main Jan 21, 2022
@jonathanpeppers jonathanpeppers deleted the no-build-tasks-in-library-packs branch January 21, 2022 18:55
@github-actions github-actions bot locked and limited conversation to collaborators Dec 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Blank MAUI shows CS0103 "The name 'InitializeComponent' does not exist in the current context"
2 participants