Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Support Visual Studio "Build Acceleration" #8581

Closed
jonathanpeppers opened this issue Dec 11, 2023 · 5 comments · Fixed by #9042
Closed

Support Visual Studio "Build Acceleration" #8581

jonathanpeppers opened this issue Dec 11, 2023 · 5 comments · Fixed by #9042
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects. enhancement Proposed change to current functionality.
Milestone

Comments

@jonathanpeppers
Copy link
Member

jonathanpeppers commented Dec 11, 2023

Android application type

.NET Android (net7.0-android, net8.0-android, etc.)

Affected platform version

.NET 8

Description

Context: https://github.com/dotnet/project-system/blob/main/docs/build-acceleration.md
Context: https://github.com/dotnet/project-system/blob/main/docs/up-to-date-check.md

Using Visual Studio 17.8, there is a new feature that skips running MSBuild "builds" in some cases during incremental builds.

This currently has an issue in Android projects:

WARNING: Potential build performance issue in 'XamarinTV.Android.csproj'.
The project does not appear up-to-date after a successful build:
Input ResolvedCompilationReference item 'C:\Users\daortin\source\repos\app-xamarintv\XamarinTV.Android\obj\Debug\net8.0-android\_Microsoft.Android.Resource.Designer.dll' (2023-12-11 11:34:12.546) has been modified since the last successful build started

There is a new item group we can add _Microsoft.Android.Resource.Designer.dll to that will solve this problem and improve build performance inside VS.

/cc @davidortinau

Steps to Reproduce

  1. Create an Android app project
  2. References an Android class library
  3. Read the diagnostic project system logs

Did you find any workaround?

No

Relevant log output

No response

@jonathanpeppers jonathanpeppers added the Area: App+Library Build Issues when building Library projects or Application projects. label Dec 11, 2023
@jonathanpeppers jonathanpeppers self-assigned this Dec 11, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issues that need to be assigned. label Dec 11, 2023
@jonathanpeppers jonathanpeppers changed the title Support Visual Studio "Build Acceleration Support Visual Studio "Build Acceleration" Dec 11, 2023
@jonathanpeppers jonathanpeppers added this to the .NET 9 milestone Dec 11, 2023
@jonathanpeppers jonathanpeppers removed the needs-triage Issues that need to be assigned. label Dec 11, 2023
@dellis1972
Copy link
Contributor

I've taken a look at the ItemGroups, I'm not sure which ones we should be using. Most of them are about files which MSBuild does NOT know about. But in this case it does.

I'll read through the source code and see what they are actually doing.

@dellis1972 dellis1972 self-assigned this Jan 4, 2024
@jonathanpeppers
Copy link
Member Author

I tested in VS 17.9 Preview 2.1 with this setting:

image

This project also has some instructions to cause it:

https://github.com/jonathanpeppers/MauiBuildAcceleration

1>FastUpToDate:         Adding ResolvedCompilationReference inputs: (MauilClassLibrary)
1>FastUpToDate:             D:\src\MauiBuildAcceleration\MauilClassLibrary\obj\Debug\net8.0-android\_Microsoft.Android.Resource.Designer.dll (MauilClassLibrary)
1>FastUpToDate: Input ResolvedCompilationReference item 'D:\src\MauiBuildAcceleration\MauilClassLibrary\obj\Debug\net8.0-android\_Microsoft.Android.Resource.Designer.dll' (2024-01-04 09:13:06.818) has been modified since the last successful build started (2024-01-04 09:13:05.405), not up-to-date. (MauilClassLibrary)

@jonathanpeppers
Copy link
Member Author

After playing with this more, the current behavior is:

  1. First build: as usual.
  2. Second (incremental) build, VS & FUTDC will run MSBuild due to the message above.
  3. Third (incremental) build, VS & FUTDC will skip running MSBuild.

Had some conversation with the project system team, and I think we could try:

  1. Hook into the CollectResolvedCompilationReferencesDesignTime target, remove the _Microsoft.Android.Resource.Designer.dll file from @(ReferencePathWithRefAssemblies):

https://github.com/dotnet/project-system/blob/e617a12f5f3e1e77ddcd7bffcbe292c706a8affe/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/DesignTimeTargets/Microsoft.Managed.DesignTime.targets#L442-L443

  1. See if that helps no. 2 above.

  2. Verify that MSBuild will still run again if you change an AndroidResource. If it doesn't, we may need to add all AndroidResource files to @(UpToDateCheckInput).

@jpobst jpobst added the enhancement Proposed change to current functionality. label Jan 24, 2024
@dellis1972
Copy link
Contributor

Odd I can't seem to repo on the latest Preview of VS...

dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Jun 19, 2024
Fixes dotnet#8581

The Visual Studio FastUpdate check flags the Resource Designer assembly as
newer than the output assembly (which it is). But it causes it to incorrectly
think the build is out of date.

```
WARNING: Potential build performance issue in 'Foo.csproj'.
The project does not appear up-to-date after a successful build:
Input ResolvedCompilationReference item 'obj\Debug\net8.0-android\_Microsoft.Android.Resource.Designer.dll' (2023-12-11 11:34:12.546) has been modified since the last successful build started
```

So lets remove it. We MUST remove the item from the @ReferencePathWithRefAssemblies
ItemGroup BEFORE the CollectResolvedCompilationReferencesDesignTime target runs.
This is because that target uses the Returns functionality. It turns out you cannot
modify the ItemGroup that is being returned via a Returns on a target.

Unfortunately there isn't a way to unit test this since the Fast Update check
ONLY runs in Visual Studio. The targets do not even exist on the command line.
@dellis1972
Copy link
Contributor

PR is up #9042

dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Jun 26, 2024
Fixes dotnet#8581

The Visual Studio FastUpdate check flags the Resource Designer assembly as
newer than the output assembly (which it is). But it causes it to incorrectly
think the build is out of date.

```
WARNING: Potential build performance issue in 'Foo.csproj'.
The project does not appear up-to-date after a successful build:
Input ResolvedCompilationReference item 'obj\Debug\net8.0-android\_Microsoft.Android.Resource.Designer.dll' (2023-12-11 11:34:12.546) has been modified since the last successful build started
```

So lets remove it. We MUST remove the item from the @ReferencePathWithRefAssemblies
ItemGroup BEFORE the CollectResolvedCompilationReferencesDesignTime target runs.
This is because that target uses the Returns functionality. It turns out you cannot
modify the ItemGroup that is being returned via a Returns on a target.

Unfortunately there isn't a way to unit test this since the Fast Update check
ONLY runs in Visual Studio. The targets do not even exist on the command line.
jonathanpeppers pushed a commit that referenced this issue Jul 1, 2024
Fixes: #8581
Fixes: https://dev.azure.com/devdiv/DevDiv/_workitems/edit/2051915

Context: https://github.com/dotnet/project-system/blob/9c9efad1d986e38232cbd74bec9dbd794883a91c/docs/build-acceleration.md 
Context: https://github.com/dotnet/project-system/blob/dd9431b535a6158060d7ab64597276eb2c354aab/docs/design-time-builds.md#targets-that-run-during-design-time-builds
Context: https://github.com/dotnet/project-system/blob/dd9431b535a6158060d7ab64597276eb2c354aab/docs/up-to-date-check.md#default-inputs-and-outputs
Context: https://github.com/dotnet/project-system/blob/dd9431b535a6158060d7ab64597276eb2c354aab/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/DesignTimeTargets/Microsoft.Managed.DesignTime.targets#L448-L449
Context: dc3ccf2

The Visual Studio Fast Up-to-Date Check (FUTDC) flags
`_Microsoft.Android.Resource.Designer.dll` (dc3ccf2) as newer than
the output assembly (which it is).  But this flagging also causes it
to incorrectly think the build is out of date.

	WARNING: Potential build performance issue in 'Foo.csproj'.
	The project does not appear up-to-date after a successful build:
	Input ResolvedCompilationReference item 'obj\Debug\net8.0-android\_Microsoft.Android.Resource.Designer.dll' (2023-12-11 11:34:12.546) has been modified since the last successful build started.

Fix this by removing `_Microsoft.Android.Resource.Designer.dll` from
the list of files checked.  To do so, we *must* remove the item from
the `@(ReferencePathWithRefAssemblies)` item group *before* the
[`CollectResolvedCompilationReferencesDesignTime`][0] target runs.
This is because that Target uses the [`Returns` attribute][1]; it
turns out you cannot modify the ItemGroup that is being returned
via the `Returns` attribute on a target.

Unfortunately there isn't a way to unit test this since the Fast Update
check *only* runs in Visual Studio.  The targets do not even exist on
the command line.

[0]: https://github.com/dotnet/project-system/blob/dd9431b535a6158060d7ab64597276eb2c354aab/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/DesignTimeTargets/Microsoft.Managed.DesignTime.targets#L448-L449
[1]: https://learn.microsoft.com/visualstudio/msbuild/target-element-msbuild?view=vs-2022
@github-actions github-actions bot locked and limited conversation to collaborators Jul 27, 2024
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
Area: App+Library Build Issues when building Library projects or Application projects. enhancement Proposed change to current functionality.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants