dotnet / wpf

WPF is a .NET Core UI framework for building Windows desktop applications.
MIT License
7.07k stars 1.17k forks source link

WPF custom control library fails to build, when `<AssemblyName>` is overriden with `$(MSBuildProjectName)` #8382

Closed AchimStuy closed 11 months ago

AchimStuy commented 1 year ago

Describe the bug

I am overriding the <AssemblyName> in my project properties, in order to have a manually strong named assembly.

Setting

<AssemblyName>MyCustomControlLibrary.$(Version)</AssemblyName>

works just as expected. But setting

<AssemblyName>$(MSBuildProjectName).$(Version)</AssemblyName>

as it is done by Microsoft.NET.Sdk.props, raises MC3050 in the Generic.xaml file: "Cannot find the type 'local:CustomControl1'."

To Reproduce

I've created a minimalistic repro at https://github.com/AchimStuy/wpf-assemblyname-from-projectname.

Exceptions (if any)

none

Further technical details

dotnet --info:

.NET SDK:
 Version:   7.0.401
 Commit:    eb26aacfec

Laufzeitumgebung:
 OS Name:     Windows
 OS Version:  10.0.22621
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\7.0.401\

Host:
  Version:      7.0.11
  Architecture: x64
  Commit:       ecb34f85ec

.NET SDKs installed:
  2.1.526 [C:\Program Files\dotnet\sdk]
  3.1.426 [C:\Program Files\dotnet\sdk]
  6.0.202 [C:\Program Files\dotnet\sdk]
  6.0.401 [C:\Program Files\dotnet\sdk]
  7.0.102 [C:\Program Files\dotnet\sdk]
  7.0.401 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.24 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.24 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.22 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.24 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

VS Info:

Microsoft Visual Studio Professional 2022
Version 17.7.4
VisualStudio.17.Release/17.7.4+34031.279
Microsoft .NET Framework
Version 4.8.09032

Installed Version: Professional

Visual C++ 2022   00476-80000-00000-AA098
Microsoft Visual C++ 2022

ASP.NET and Web Tools   17.7.273.65229
ASP.NET and Web Tools

Azure App Service Tools v3.0.0   17.7.273.65229
Azure App Service Tools v3.0.0

Azure Functions and Web Jobs Tools   17.7.273.65229
Azure Functions and Web Jobs Tools

C# Tools   4.7.0-3.23416.8+43b0b05cc4f492fd5de00f6f6717409091df8daa
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Clean Solution   1.4.35
Cleans up the solution for the next time you open it. Closes open documents and collapses folders automatically when a solution is being closed.

Clear MEF Component Cache   1.4
Clears the Visual Studio MEF component cache to fix issues with cache corruption.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Developer News 2022   1.0.83
Always stay up to date with developer news from the Visual Studio team and other sources right within Visual Studio or your default browser.

Entity Framework Core Power Tools   2.5
Adds useful design-time EF Core DbContext features to the Visual Studio Solution Explorer context menu.

Extensibility Essentials 2022   1.1.14
A collection of extensions that makes it much easier to write Visual Studio extensions

Extensibility Margin   1.0.9
Shows relevant information about the current file and language to extensibility authors

Extensibility Message Bus   1.4.34 (main@d5ab18b)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

File Icons   2.7
Adds icons for files that are not recognized by Solution Explorer

Image Manifest Tools   1.1.8
Makes it easier to create and maintain .imagemanifest files for Visual Studio extension

Increment Version on Build   1.2022.906.1300
Increment Version on every build according to configureable rules.

KnownMonikers Explorer 2022   1.2.42
A tool window for Visual Studio extension authors to explore the KnownMonikers image collection

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Mono Debugging for Visual Studio   17.7.27 (547ea6f)
Support for debugging Mono processes with Visual Studio.

Pkgdef Language   1.3.91
Full language support with IntelliSense, validation, outlining, and more for .pkgdef and .pkgundef files

Razor (ASP.NET Core)   17.7.3.2333001+0ab18affdf2a37647768d0e25f5f021bee6257a1
Provides languages services for ASP.NET Core Razor.

Scroll Tabs   1.0.22
Allows you to scroll through open document tabs using the mouse wheel

SonarLint for Visual Studio   7.3.0.77872
SonarLint is an extension to your favorite IDE that provides on-the-fly feedback to developers on new bugs and quality issues injected into their code.

SQL Server Data Tools   17.7.10.1
Microsoft SQL Server Data Tools

SQLite & SQL Server Compact Toolbox   4.8
SQLite & SQL Server Compact Toolbox adds scripting, import, export, rename, query execution and much more to SQL Server Compact & SQLite Data Connections.

TypeScript Tools   17.0.20829.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   4.7.0-3.23416.8+43b0b05cc4f492fd5de00f6f6717409091df8daa
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools   17.7.0-beta.23314.10+e612cf93b989503c89e3a5830090062b7ab5e143
Microsoft Visual F# Tools

Visual Studio IntelliCode   2.2
AI-assisted development for Visual Studio.

VisualStudio.DeviceLog   1.0
Information about my package

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

VS Theme Colors 2022   1.0.11
Makes it easy to browse all the brushes and select the right theme color for your Visual Studio extension UI.

VSIX Synchronizer   1.0.27
Provides the ability to generate code-behind files for .vsixmanfiest and .vsct files in managed code to make the information easy to consume from the rest of the extension.

VSPackage Extension   1.0
VSPackage Visual Studio Extension Detailed Info

WiX Toolset Visual Studio Extension   1.0.0.18
WiX Toolset Visual Studio Extension version 1.0.0.18
Copyright (c) .NET Foundation and contributors. All rights reserved.

Xamarin   17.7.0.216 (d17-7@133ddef)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   17.7.3.9 (remotes/origin/d17-7@796d191def)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin.Android SDK   13.2.1.2 (d17-5/a8a26c7)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: d9a6e87
    Java.Interop: xamarin/java.interop/d17-5@149d70fe
    SQLite: xamarin/sqlite/3.40.1@68c69d8
    Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-5@ca1552d
baronfel commented 1 year ago

Since this is an issue with WPF and how it determines properties for it's inner builds, I am going to move it to that repo for troage.

Kuldeep-MS commented 1 year ago

Hi @AchimStuy, it seems that this problem is duplicate of the one described in https://github.com/dotnet/wpf/issues/5711. Could you please attempt the solution provided there and inform us if it resolves the issue?

AchimStuy commented 1 year ago

Hi @Kuldeep-MS, yes, this workaround is working. But I want to state, that it's only a workaround and not a solution.

Kuldeep-MS commented 1 year ago

Hello @AchimStuy, I'm pleased to hear that the solution I provided is working for you. However, could you please explain why you consider it a workaround rather than a permanent fix? Additionally, what do you believe would be the optimal solution to resolve the issue?

AchimStuy commented 1 year ago

Hi @Kuldeep-MS,

thanks for asking!

I am expecting WPF build to work out of the box without adding

<AssemblyName Condition="$(_TargetAssemblyProjectName) != ''">$(_TargetAssemblyProjectName).$(Version)</AssemblyName>

to every project. (Though I don't know how, but you're the expert.) Because I am managing the $(Version) inside the .csproj file, I can't just add the line to a global .props file.

The line above is an additional line, which must be documented and all the stuff is cluttering my project files, that I could also hard code the assembly name, but would lose the dynamic AssemblyName functionality.

Kuldeep-MS commented 1 year ago

Hi @achimStuy, sorry for the confusion earlier. I was actually referring to the fix that I submitted three months ago, not the workaround that was shared on the issue. Link To Fix - https://github.com/dotnet/wpf/pull/7557

Could you please take a look at the fix? I am hopeful that it will work. You can find instructions for checking the fix in the documentation provided here.

Kuldeep-MS commented 12 months ago

Hi @AchimStuy, could you kindly review my previous comment and inform us if the solution provided has resolved your issue? This will allow us to close the issue.

AchimStuy commented 12 months ago

Sorry, @Kuldeep-MS, I'm on a business trip this week, so I don't have time to look into it. You will hear from me next week.

Just that I am doing the right things: I must clone the repo, build and replace the files at C:\Program Files\dotnet\Sdk\ with my built files and then try again to build?

AchimStuy commented 11 months ago

@Kuldeep-MS, yes, I can confirm, that your PR fixes the issue.

Kuldeep-MS commented 11 months ago

@AchimStuy - Thanks for your confirmation. Closing this Issue.