dotnet / project-system

The .NET Project System for Visual Studio
MIT License
969 stars 387 forks source link

<EnableDefaultCompileItems>false</EnableDefaultCompileItems> partially working #7002

Open baskren opened 3 years ago

baskren commented 3 years ago

Visual Studio Version: VisualStudio 2019 v16.9.0

Summary: The <EnableDefaultCompileItems>false</EnableDefaultCompileItems> MSBuild property is not completely working. Specifically, using it, in combination with platform specific <Compile Include="**\*.platform_suffix_here.cs" /> Items, results in filtering platform specific files in some cases but not others.

Sample Project: https://github.com/baskren/VisualStudio.CrossPlatformProjects1.git

In the above solution, there are 8 platform specific Library projects: image

For common build properties and items, there is a Directory.Build.props file in the same folder as the platform specific projects for the library. It is as follows:

<Project ToolsVersion="15.0">

  <PropertyGroup>

    <GenerateLibraryLayout>true</GenerateLibraryLayout>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>

    <AssemblyName>CrossPlatformLibrary1</AssemblyName>
    <RootNamespace>CrossPlatformLibrary1</RootNamespace>

    <NoWarn>Uno0001</NoWarn>

    <BaseOutputPath>bin\$(MSBuildProjectName)</BaseOutputPath>
    <BaseIntermediateOutputPath>obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>

    <EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems>
    <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
    <DefaultItemExcludes>$(DefaultItemExcludes);obj/**;bin/**</DefaultItemExcludes>

    <DebugType>portable</DebugType>

  </PropertyGroup>

  <PropertyGroup Condition=" '$(Configuration)'=='Debug' ">
    <DebugSymbols>true</DebugSymbols>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="**\*.shared.cs" />
    <Compile Include="**\*.shared.*.cs" />

    <PackageReference Include="Uno.UI" Version="3.5.1" />
  </ItemGroup>

</Project>

Notice the <EnableDefaultCompileItems>false</EnableDefaultCompileItems> on line 17 (above).

Each platform specific project for the library looks something like this:

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="MSBuild.Sdk.Extras/3.0.22">
  <PropertyGroup>
    <TargetFrameworks>monoandroid10.0</TargetFrameworks>
  </PropertyGroup>

  <PropertyGroup Condition=" '$(Configuration)'=='Debug' ">
    <DebugSymbols>true</DebugSymbols>
    <WarningLevel>5</WarningLevel>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="**\*.android.cs" />
    <Compile Include="**\*.android.*.cs" />

    <PackageReference Include="Xamarin.AndroidX.Browser" Version="1.3.0" />
    <PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />    

    <Reference Include="System.Numerics" />

    <AndroidResource Include="Resources\xml\*.xml" />
  </ItemGroup>

</Project>

The below screen shot illustrates the issue: image

Notice that some CrossPlatformLibrary1 platform projects (Skia.Gtk, Skia.Tizen, Skia.Wpf, and Wasm, in this example) are correctly filtering where as the other projects (Android, iOS, MacOS, and UWP) are not.

Steps to Reproduce:

  1. Open the solution found at : https://github.com/baskren/VisualStudio.CrossPlatformProjects1.git

  2. In Solution Explorer, examine the platform projects for each platform project in the Library folder

Expected Behavior:

Mis-matched platform specific files are filtered out of each platform project (ex: Class1.ios.cs does not appear in the CrossPlatformLibrary1.Android project listing in Solution Explorer

Actual Behavior:

Mis-matched platform specific files are NOT filtered out of each platform project (ex: Class1.ios.cs, as well as others, appears in the CrossPlatformLibrary1.Android project listing in Solution Explorer image

User Impact:

Low to moderate. Fortunately, the build process IS WORKING. This is a VisualStudio 2019 v16.9.0 issue (it was not happening in last release of version 16.8).

dsplaisted commented 3 years ago

@baskren Thanks a lot for the detailed repro. I'm sure that will be helpful

@jjmew To assign for triage / investigation

This may be related to the fact that there are multiple library projects in the same folder with different globs