3xGuy
3xGuy

Reputation: 2559

dotnet build doesn't work with 1 WPF project but all others do

I'm having an issue with dotnet-cli. and WPF, when I right-click the solution and choose build it works every time. No issues, but when I open Developer Powershell and type dotnet build it doesn't compile. It gives me error:

the name 'InitializeComponent' does not exist in the current context

I have googled and seen several issues all of which from my understanding does not work with ms build.

Additional Info - .net framework 4.7.2

Why would I get this error with cli and not ms build?

Upvotes: 1

Views: 255

Answers (1)

RoryStark
RoryStark

Reputation: 11

In case anyone else happens upon this, it looks to be a .NET Framework issue that won't be fixed: https://developercommunity.visualstudio.com/t/the-name-initializecomponent-does-not-exist-in-the-1/746339#T-N1213090

We determined that this is a bug in WPF .NET Framework not Visual Studio. Since .NET Framework is no longer under active development, only extremely impactful issues are being fixed there. For example, security issues or issues affecting large numbers of developers. Given that this feedback ticket has been open for a year and has received very few votes, I believe it does not fall into this bucket.

I suggest that you migrate to WPF .NET Core if possible, since that is under active development and any issues you might encounter there would be much more likely to be fixed. If you do run into WPF .NET Core issues, you can report them at https://github.com/dotnet/wpf/issues and they will be considered for .NET 6.0.

My team will moved off of Framework at some point (for the most part), but in the meantime, my workaround (for our purposes) has been to call the latest MsBuild.exe via:

>for /f "tokens=*" %a in ('@"%ProgramFiles(x86)%\Microsoft Visual Studio"\Installer\vswhere.exe -latest -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe') do %a MyFrameworkWPFProject.csproj

This utilizes the vswhere utility to grab the latest (in terms of VS installs).

Upvotes: 0

Related Questions