question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WPF: Build fails in wpftmp.csproj when `ThisAssembly` is used

See original GitHub issue

I am trying to embed the library within a WPF app targeting netcoreapp3.0.

Repro

  1. Create WPF (.NET Core) via Visual Studio 2019.
  2. Create Git repository via Git UI in VS.
  3. Install NerdBank.GitVersioning via NuGet UI.
  4. Add Title = ThisAssembly.GitCommitId; to the MainWindow constructor.
  5. Try to build the application.

The IntelliSense suggests ThisAssembly and also shows the right constant values in the tooltip (the class is generated somewhere), but when it comes the build:

1>------ Build started: Project: VersioningTest, Configuration: Debug Any CPU ------
1>MainWindow.xaml.cs(13,21,13,33): error CS0103: The name 'ThisAssembly' does not exist in the current context
1>Done building project "VersioningTest_deh445kx_wpftmp.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

What I tried then

  1. If you remove the line added in 3 the app successfully builds & runs. When you add the line Title = typeof(MainWindow).Assembly.GetName().Version.ToString(); instead the version is 0.0.0.0.
  2. During installation no version.json was created. I added one on project level and as this did not work in the git root which didn’t work either.
  3. I executed nbgv install via packet manager console on solution(= git repo root) level, after installing it as a global tool. Still did not work. On project level did not work either (created files at same location).
  4. Used Title = typeof(MainWindow).Assembly.GetName().Version.ToString(); and nbgv install. Version displayed is 1.0.0.0.

Context

My project file:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <UseWPF>true</UseWPF>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Nerdbank.GitVersioning" Version="3.0.26">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>

</Project>

I did not find any issues related to this issue.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
inthemediumcommented, Feb 4, 2021

To aid others, I found another instance where the workaround above fixes the issue below. You can get in this situation with usage of InternalsVisibleTo in dependencies of a WPF project.

SomeFileUnderAWpfProject.cs(42,42): error CS0433: The type 'ThisAssembly' exists in both 'AssemblyA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' and 'AssemblyB, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' [wpfproject_x3jmmw55_wpftmp.csproj]

1reaction
hypervtechnicscommented, Nov 15, 2019

Now it is working. Thank you for the quick workaround 😄 !

Read more comments on GitHub >

github_iconTop Results From Across the Web

msbuild is adding a random hash and wpftmp to my ...
A team I'm working with gave me a C# Windows Application, and when I build it in VS2017, I see in the build...
Read more >
WPF application build fails with "Program does not contain ...
WPF application build fails with "Program does not contain a static 'Main' method" using MSBuild from SDK 6.0 instead of bundled MSBuild in ......
Read more >
.NET 6 XAML Markup Compiler Mayhem - omni's hackpad
I was excited to upgrade to the new .NET 6, but much less excited to see it generating strange temporary assemblies borking my...
Read more >
Build in Visual Studio runs fine, msbuild fails
We need to build a msix package (wapproj) with our DevOps pipeline. We only want to build for platform x64 on windows for...
Read more >
Building a WPF .NET Core project referencing ...
NET Core project referencing DevExpress .NET Core assemblies causes the 'Could not find assembly 'System.Drawing.Common' build error.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found