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

Imported NuGet .targets causes additional project platforms to be displayed #1755

Open
sgarske opened this issue Sep 21, 2021 · 3 comments
Open
Labels
bug Something isn't working priority-low We have considered this issue and decided that we will not be able to address it in the near future. tracked We are tracking this work internally.

Comments

@sgarske
Copy link

sgarske commented Sep 21, 2021

Description

After installing the Microsoft.Web.Webview2 NuGet package onto a C# class library (.NET Framework) project, Visual Studio will display additional project platforms that are not defined in the .csproj.

Default project platforms after creating project
image

After installing NuGet package
image

Version
SDK: At least 1.0.705.50 of Microsoft.Web.Webview2 NuGet package or later (also confirmed with 1.0.1018-prerelease )
Runtime: N/A?
Framework: Confirmed with a WPF application project/solution and a C# Wix Custom Action library
OS: Win10

Repro Steps

  1. Create a new C# Class Library (.NET Framework) project
  2. Install latest Microsoft.Web.Webview2 NuGet package
  3. Close/re-open solution
  4. View the detected "Platforms" in the project properties

I expected no additional Platforms to show besides what are defined by my project. By installing the package and the import of the .targets, additional platforms show.

Additional context

I believe this has to do with the setting of EffectivePlatform at the beginning of Common.targets ( automatically imported by Microsoft.Web.WebView2.targets )

<?xml version="1.0"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <!-- The Platform property is Win32 or x64 for C++ projects. Convert from Win32 to x86 to match our directory structure.
    If PlatformTarget property is set, then use that to determine EffectivePlatform for .NET projects.
    See conditions: https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-conditions?view=vs-2019
    and PropertyGroup: https://docs.microsoft.com/en-us/visualstudio/msbuild/propertygroup-element-msbuild?view=vs-2019
  -->
  <PropertyGroup>
    <EffectivePlatform>$(Platform)</EffectivePlatform>
    <EffectivePlatform Condition="'$(Platform)' == 'Win32'">x86</EffectivePlatform>
    <EffectivePlatform Condition="'$(Platform)' == 'Any CPU'">x86</EffectivePlatform>
    <EffectivePlatform Condition="'$(Platform)' == 'AnyCPU'">x86</EffectivePlatform>
...

I believe by just checking for conditional platforms that don't exist in the project, it triggers the project UI to show them as possible options. This causes confusion of which platforms are actually available.

I removed these lines and the issue went away.

Honestly, it feels like it may be an issue with Visual Studio and the project structure, but maybe that's just how it works? Possibly the NuGet targets can add a conditional to the whole PropertyGroup since it's not even needed in the .NET project case.

Thanks for reading/considering.

AB#36410393

@sgarske sgarske added the bug Something isn't working label Sep 21, 2021
@champnic champnic added the tracked We are tracking this work internally. label Sep 23, 2021
@champnic
Copy link
Member

Thanks for the bug report @sgarske! I've added it to our backlog. It is surprising that Visual Studio would be so proactive about adding platforms based on a condition check!

@github-actions github-actions bot added the priority-low We have considered this issue and decided that we will not be able to address it in the near future. label Mar 26, 2024
@jhennessey
Copy link

Can confirm this is still an issue today.

Simply using $(EffectivePlatform) instead of $(Platform) in the conditions (since it already has the Platform value) should fix this issue. You could also just copy the value of $(Platform) to a temporary property as well.

So this code:

  <PropertyGroup>
    <EffectivePlatform>$(Platform)</EffectivePlatform>
    <EffectivePlatform Condition="'$(Platform)' == 'Win32'">x86</EffectivePlatform>
    <EffectivePlatform Condition="'$(Platform)' == 'Any CPU'">x86</EffectivePlatform>
    <EffectivePlatform Condition="'$(Platform)' == 'AnyCPU'">x86</EffectivePlatform>

Becomes either this:

  <PropertyGroup>
    <EffectivePlatform>$(Platform)</EffectivePlatform>
    <EffectivePlatform Condition="'$(EffectivePlatform)' == 'Win32'">x86</EffectivePlatform>
    <EffectivePlatform Condition="'$(EffectivePlatform)' == 'Any CPU'">x86</EffectivePlatform>
    <EffectivePlatform Condition="'$(EffectivePlatform)' == 'AnyCPU'">x86</EffectivePlatform>
...

Or this:

  <PropertyGroup>
    <CurrentPlatform>$(Platform)</CurrentPlatform>
    <EffectivePlatform>$(CurrentPlatform)</EffectivePlatform>
    <EffectivePlatform Condition="'$(CurrentPlatform)' == 'Win32'">x86</EffectivePlatform>
    <EffectivePlatform Condition="'$(CurrentPlatform)' == 'Any CPU'">x86</EffectivePlatform>
    <EffectivePlatform Condition="'$(CurrentPlatform)' == 'AnyCPU'">x86</EffectivePlatform>
...

Would love to see this fixed soon as it causes a headache for tools that parse projects via the MSBuild API.

My current use case is writing a tool to automatically update legacy csproj files and add a Platforms property that contains all valid platforms for the project. This is required in order to make use of the SetPlatform Negotiation feature in MSBuild. Right now, all projects referencing this package end up with invalid platforms.

@champnic
Copy link
Member

I've just put in a quick fix for this. I think it just missed the cutoff for the next prerelease SDK, but should be available in the following one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority-low We have considered this issue and decided that we will not be able to address it in the near future. tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests

3 participants