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 Acceleration with netstandard #8865

Closed
Tracked by #8760
persn opened this issue Feb 22, 2023 · 7 comments
Closed
Tracked by #8760

Build Acceleration with netstandard #8865

persn opened this issue Feb 22, 2023 · 7 comments
Labels
Feature-Build-Acceleration Build Acceleration can skip calls to MSBuild within Visual Studio
Milestone

Comments

@persn
Copy link

persn commented Feb 22, 2023

Visual Studio Version

Version 17.5.0

Summary

I was going to try and see if we could use build acceleration at my workplace, however I couldn't make it trigger and it always built all my project dependencies when I made a simple edit in one of the source files at one of our core libraries. Eventually I discovered that if I changed the target framework to net6.0 from netstandard2.0 it worked as expected.

I can understand there might be some technical reason netstandard projects doesn't get build acceleration, not sure if that is the case, but if it is it should probably be listed as a prerequisite, which AFAICT it is not https://github.com/dotnet/project-system/blob/main/docs/build-acceleration.md#validate-builds-are-accelerated

Steps to Reproduce

Using this as an example.. If Library 3 has target framework netstandard2.0, and I make a change to to Library 3, it will trigger all 4 MSBuild calls instead of being called once like it states in the link. If I change to net6.0 it works as expected, it also works if I multi-target <TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>.

Expected Behavior

I would expect projects with netstandard to support build acceleration as I can't see any documentation that states otherwise, or I would expect the documentation to make target framework demands more clear.

Actual Behavior

Build acceleration doesn't trigger when I make a simple change in one of my core libraries, instead the entire source gets built like it always did. Documentation doesn't mention any target framework requirements

User Impact

We have a very large codebase that we're working on migrating to net6.0, however the majority of the codebase will have to continue to build to netstandard until we we can rid ourselves of all legacy demands which will take along time. Without netstandard support we cannot use this feature which otherwise looks excellent.

drewnoakes added a commit to drewnoakes/sdk that referenced this issue Feb 23, 2023
In general we want to produce reference assemblies whenever possible, as they improve incremental build performance.

However they require support from other components, such as the fast up-to-date check in VS. While support was originally added for SDK-style projects, it was not present for legacy `.csproj` files. Accordingly, `ProduceReferenceAssemblies` was set `true` only when the target framework was `net5.0` or later (and `net7.0` for F#).

VS 17.5 ships the new Build Acceleration feature, which works best when used in conjunction with reference assemblies. A customer reported in dotnet/project-system#8865 that builds in their .NET Standard projects were not accelerated. Investigation shows this is because reference assemblies are not produced for such projects.

This change enables the production of reference assemblies for all (non-F#) projects targeting .NET Standard.
@drewnoakes
Copy link
Member

@persn thanks very much for the feedback! I've taken a look and understand the issue.

tl;dr: Add property <ProduceReferenceAssembly>true</ProduceReferenceAssembly> to your projects.

Build Acceleration works best when your solution is configured to produce reference assemblies. By default, whether reference assemblies are produced depends upon the target framework.

For back-compat reasons, ProduceReferenceAssembly was only set to true by default when targeting net5.0 or later. No provision was made for netstandard*.*. I suspect enough time has passed now that we can revisit these defaults to include more projects, and filed dotnet/sdk#30792 to cover your case. I'll start a discussion between some VS teams, MSBuild and the SDK as to whether we can change the defaults to be even more permissive in future.

We have work item #8798 which would have prompted you to be able to address this yourself, and I hope to get that into 17.6.

In the meantime, it should be straightforward for you to set ProduceReferenceAssembly alongside your AccelerateBuildsInVisualStudio property.

I'll be sure to add this information to the documentation for future.

Thanks again for the feedback. Please try out the above and let me know if it works for you.

@drewnoakes
Copy link
Member

#8870 will help identify cases like this in 17.6 and later.

@persn
Copy link
Author

persn commented Feb 23, 2023

I have tested now, and it worked pretty much instantly when I set <ProduceReferenceAssembly>true</ProduceReferenceAssembly> in my Directory.Build.props. Which makes this seem stable enough that I'll apply those changes to our main branch and then I'll see if any other issues pop up when the rest of the devs starts compiling code. Will open new issues in that event.

Just for fun, here are some numbers I gathered when testing editing on of our core libraries in our largest solution followed by a build:

Visual Studio 17.5 without Build Acceleration

  1. 04:24:057
  2. 03:46:149
  3. 04:17:786
  4. 03:40:603
  5. 03:44:969

Visual Studio 17.5 with Build Acceleration

  1. 00:07:309
  2. 00:05:483
  3. 00:05:459
  4. 00:05:767
  5. 00:05:273

@drewnoakes
Copy link
Member

@persn thanks for confirming. I'm really glad to see the feature's had such a huge impact on your build times!

@jamesc-skyward
Copy link

Is this intended to work with .NET Framework using SDK-style projects?

@drewnoakes
Copy link
Member

drewnoakes commented Feb 24, 2023

@jamesc-skyward yes, this will work. In fact, this very repo targets .NET Framework with SDK-style projects and uses Build Acceleration.

A few caveats though:

  • You need to ensure ProduceReferenceAssembly is set to true for your projects. The default for .NET Framework projects is false. Producing reference assemblies is a good idea regardless of whether you're using Build Acceleration.
  • Targeting .NET Framework from SDK-style projects is not technically supported, however we do our best to make this work and are not aware of any major blockers.

@drewnoakes drewnoakes added this to the 17.6 milestone Feb 24, 2023
@drewnoakes drewnoakes added the Feature-Build-Acceleration Build Acceleration can skip calls to MSBuild within Visual Studio label Feb 24, 2023
@drewnoakes
Copy link
Member

drewnoakes commented Feb 24, 2023

I'm going to close this as complete. Build Acceleration is working for you. We've extended the documentation with details for others to benefit from. We've added log output to warn about this situation in 17.6. I'm working to have .NET Standard projects produce reference assemblies by default.

Thanks again for the feedback. Do let us know if you have any other thoughts or issues with the feature.

christophwille added a commit to icsharpcode/ILSpy that referenced this issue Jun 26, 2023
…puts have the 'ProduceReferenceAssembly' MSBuild property set to 'true': 'D:\GitWorkspace\ILSpy\ICSharpCode.Decompiler\bin\Debug\netstandard2.0\ICSharpCode.Decompiler.dll'" - this relates to the documented problem of netstandard2.0 projects not generating the necessary reference assemblies (direct issue link dotnet/project-system#8865) No harm for netcore projects as these produce those ref asms by default.
christophwille added a commit to icsharpcode/ILSpy that referenced this issue Jul 24, 2023
* Accelerate builds of SDK-style .NET projects https://github.com/dotnet/project-system/blob/main/docs/build-acceleration.md#validate-builds-are-accelerated

* Verbose logging produced "Ensure projects producing the following outputs have the 'ProduceReferenceAssembly' MSBuild property set to 'true': 'D:\GitWorkspace\ILSpy\ICSharpCode.Decompiler\bin\Debug\netstandard2.0\ICSharpCode.Decompiler.dll'" - this relates to the documented problem of netstandard2.0 projects not generating the necessary reference assemblies (direct issue link dotnet/project-system#8865) No harm for netcore projects as these produce those ref asms by default.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature-Build-Acceleration Build Acceleration can skip calls to MSBuild within Visual Studio
Projects
None yet
Development

No branches or pull requests

3 participants