Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does <ImportWindowsDesktopTargets> do in a try-convert generated *.csproj?

Tags:

c#

csproj

.net-5

I have used the try-convert tool to convert my projects from .NET Framework to .NET 5.0

When inspecting the converted *.csproj files for projects that are targeting .net50-windows I noticed the element:

<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>

I am curious to understand what it does?

Is this essential or another example of something that try-convert puts in the *.csproj but is not really required to be present in the *.csproj any more?

like image 370
Cleve Avatar asked Dec 06 '25 03:12

Cleve


2 Answers

The same happened when I used upgrade-assistant to do the upgrade and I also wondered what the ImportWindowsDesktopTargets means and whether I needed it. I could find no official documentation for it, only this discussion. According to the question in the discussion, adding an ImportWindowsDesktopTargets property is one way to allow multitargetting using the TargetFramworks property, like this:

<TargetFrameworks>net472;net5.0-windows</TargetFrameworks>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>

As my project does not need to target multiple frameworks, just net5.0-windows, and as I have other projects, both Windows Forms and WPF, that target only net5.0-windows and work fine without ImportWindowsDesktopTargets, I removed ImportWindowsDesktopTargets from the converted project with no problems.

According to the proposed answer in the linked discussion, even if you do want to target multiple frameworks, there may be a better way to do it.

like image 173
SimonOR Avatar answered Dec 08 '25 17:12

SimonOR


This is for pre-Net5.0 behavior to force importing WindowsDesktop Targets. If you are using Net 5.0 or a newer version, Microsoft.NET.Sdk.WindowsDesktop will always be imported by the SDK, so you may remove it.

like image 37
Mohammad Karimi Avatar answered Dec 08 '25 18:12

Mohammad Karimi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!