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

NB.GV defeats incremental build for .NET SDK style WPF projects #175

Closed
jviau opened this issue May 1, 2018 · 12 comments
Closed

NB.GV defeats incremental build for .NET SDK style WPF projects #175

jviau opened this issue May 1, 2018 · 12 comments

Comments

@jviau
Copy link

jviau commented May 1, 2018

Nerdbank gitversion is incompatible with WPF targets and SDK projects. Either ThisAssembly will be inaccessible due to protection level, or the generation of Version.cs in the WPF temp project breaks incremental build.

From my investigation, I believe 3 things are needed:

  1. Make GenerateAssemblyVersionInfo run before MarkupCompilePass1
  2. Do not run GenerateAssemblyVersionInfo inside the WPF temporary project.
  3. Re-include the Version.cs generated from the original project in the WPF temporary project.

See https://devdiv.visualstudio.com/DevDiv/VS%20IDE%20CPS/_git/CPS/pullrequest/120052?_a=overview for the workarounds I performed to get this to work.

@jviau jviau changed the title Incompatible with SDK that include WPF xaml compilation Incompatible with SDK style projects that include WPF xaml compilation May 1, 2018
@AArnott
Copy link
Collaborator

AArnott commented May 2, 2018

I think the first thing that needs to be fixed for this scenario to work is NuGet/Home#5894. Without PackageReference working properly for WPF projects, it's going to fail regardless of what we do in the NB.GV package.

@jviau
Copy link
Author

jviau commented May 2, 2018

I opened dotnet/msbuild#3254 for that issue.

They both need to be fixed IMO, order doesn't matter. In my experience it was much harder to discover and solve this NB.GV issue than the WPF import issue. That one was relatively simple. WPF tmp_proj gets the same $(AssemblyName) as the original project, and my assembly names match the project name. So I used that to build the imports in Directory.Build.props/targets when I am in a WPF project - which can be detected by testing for '.tmp_proj'.

@AArnott
Copy link
Collaborator

AArnott commented May 2, 2018

They both need to be fixed IMO

No argument there. Just that it's a low priority for me to fix an issue in a scenario Microsoft doesn't support, whose workaround is not straightforward. I'm still investigating, but at this stage I'm just trying to get a repro (with the workaround applied) so I can see the problem. And the nuget bug makes it difficult.

@AArnott
Copy link
Collaborator

AArnott commented May 2, 2018

OK, so I've finished applying a workaround for the WPF nuget import issue. After that, NB.GV works. This matches the experience I have in the VS-Platform repo where we have several such WPF projects that use NB.GV.
I don't understand the claim that it's incompatible.

You mentioned an incremental build regression with NB.GV. Is that really the only issue?

@jviau
Copy link
Author

jviau commented May 2, 2018

It is the incremental build issue. MarkupCompilePass1 has an incremental build step that checks the timestamp of all input files. Version.cs is the one that always fails that check. The WPF temp project will touch the version.cs and version.cs.new file, and then the real project will touch it again after. So every build causes a full build, as MarkupCompilePass1 will return true for needing to compile main assembly. Disabling generation of this file within WPF isn't sufficient either, as then it won't exist until after WPF runs, causing build errors.

@AArnott AArnott changed the title Incompatible with SDK style projects that include WPF xaml compilation NB.GV defeats incremental build for .NET SDK style WPF projects May 2, 2018
@AArnott
Copy link
Collaborator

AArnott commented May 2, 2018

I create version.cs.new first and compare it with version.cs before overwriting version.cs specifically to keep incremental build working. How does touching version.cs.new break incremental build, seeing as it's not a compile input? And I don't touch version.cs at all unless it changed.

@jviau
Copy link
Author

jviau commented May 2, 2018

I updated my comment above. I debugged into MarkupCompilePass1, and its incremental build check always failed when checking the timestamp of Version.cs. The fix I linked of ensuring Version.cs is created before wpf targets run, and then not generating that file within the wpf temp proj resolved it for me.

@clairernovotny
Copy link
Member

@AArnott FWIW, the SDK Extras 1.5.4 includes a fix for the WPF imports stuff based on a new variable they set.

AArnott pushed a commit that referenced this issue Sep 5, 2022
Bumps [Microsoft.NET.Test.Sdk](https://github.com/microsoft/vstest) from 17.2.0 to 17.3.1.
- [Release notes](https://github.com/microsoft/vstest/releases)
- [Commits](microsoft/vstest@v17.2.0...v17.3.1)

---
updated-dependencies:
- dependency-name: Microsoft.NET.Test.Sdk
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@KirillOsenkov
Copy link
Member

Related discussion in #642 (comment)

@AArnott
Copy link
Collaborator

AArnott commented Sep 30, 2023

The problem is the WPF inner build and outer build define different root namespace, so the generated assemblyinfo file is different from inner to outer builds:

31c31
<     internal const string RootNamespace = "fix642_clrmgcrv_wpftmp";
---
>     internal const string RootNamespace = "fix642";

So a workaround would be to set RootNamespace in the WPF project file explicitly so it doesn't inherit from the project filename.
This should be fixed with dotnet/wpf#5697, but for folks using older SDKs, NB.GV may be able to do something clever here.

@KirillOsenkov
Copy link
Member

Ah, interesting! Thanks for digging in!

AArnott added a commit that referenced this issue Sep 30, 2023
@KirillOsenkov
Copy link
Member

Confirmed setting RootNamespace fixes the incremental build. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants