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

Condition on csproj ItemGroup item removes entire line from output #7027

Open
krjone01 opened this issue Sep 11, 2023 · 2 comments
Open

Condition on csproj ItemGroup item removes entire line from output #7027

krjone01 opened this issue Sep 11, 2023 · 2 comments

Comments

@krjone01
Copy link

Product

dotnet CLI (dotnet new)

Describe The Bug

When using a condition on a msbuild ItemGroup item in a template csproj file, the entire line is removed from the output csproj file. This is a "Microsoft.NET.Sdk.Web" project file.

The fragment from the template csproj file

  <!-- main app -->
  <ItemGroup>
    <NgAppInput Include="$(SpaRoot)\src\**" />
    <NgAppOutput Include="$(SpaRoot)\dist\main\**" Exclude="$(SpaRoot)\dist\main\favicon.ico" />
         <!-- Item group can't be empty, but the file does not have to exist. Use fake file for no output files -->
         <!--
      For some unknown reason the line below is being removed from the template output
      You may have to copy and paste it back into the project file.
      <NgAppOutput Include="$(SpaRoot)\fake.file" Condition="@(NgAppOuput->Count()) == 0" />
     -->
    <NgAppOutput Include="$(SpaRoot)\fake.file" Condition="@(NgAppOuput->Count()) == 0" />
  </ItemGroup>

This is the fragment from the csproj file after dot net new

 <!-- main app -->
  <ItemGroup>
    <NgAppInput Include="$(SpaRoot)\src\**" />
    <NgAppOutput Include="$(SpaRoot)\dist\main\**" Exclude="$(SpaRoot)\dist\main\favicon.ico" />
         <!-- Item group can't be empty, but the file does not have to exist. Use fake file for no output files -->
         <!--
      For some unknown reason the line below is being removed from the template output
      You may have to copy and paste it back into the project file.
     -->
  </ItemGroup>

Note that not only is the line removed from the project file, its also removed from the XML comment so it seems like some sort of parsing issue.

I have messed around with the condition and the only reliable way to get the line to come out is to remove any kind of comparison from the condition. Of course, this does not produce the desired result.

  <!-- main app -->
  <ItemGroup>
    <NgAppInput Include="$(SpaRoot)\src\**" />
    <NgAppOutput Include="$(SpaRoot)\dist\main\**" Exclude="$(SpaRoot)\dist\main\favicon.ico" />
                  <!-- Item group can't be empty, but the file does not have to exist. Use fake file for no output files -->
                  <!--
      For some unknown reason the line below is being removed from the template output
      You may have to copy and paste it back into the project file.
      <NgAppOutput Include="$(SpaRoot)\fake.file" Condition="@(NgAppOuput->Count())" />
     -->
    <NgAppOutput Include="$(SpaRoot)\fake.file" Condition="@(NgAppOuput->Count())" />
  </ItemGroup>

To Reproduce

Steps:

  1. Create an ItemGroup in the csproj template file
  2. Add a ItemGroup item with a valid condition attribute
  3. Process the template through dot net new

dotnet Info

output NET SDK:

Version: 7.0.400

Commit: 73bf45718d

Runtime Environment:

OS Name: Windows

OS Version: 10.0.19045

OS Platform: Windows

RID: win10-x64

Base Path: C:\Program Files\dotnet\sdk\7.0.400\

Host:

Version: 7.0.10

Architecture: x64

Commit: a6dbb800a4

.NET SDKs installed:

3.1.426 [C:\Program Files\dotnet\sdk]

6.0.413 [C:\Program Files\dotnet\sdk]

7.0.400 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:

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.21 C:\Program Files\dotnet\shared[Microsoft.AspNetCore.App]

Microsoft.AspNetCore.App 7.0.10 C:\Program Files\dotnet\shared[Microsoft.AspNetCore.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.15 C:\Program Files\dotnet\shared[Microsoft.NETCore.App]

Microsoft.NETCore.App 6.0.21 C:\Program Files\dotnet\shared[Microsoft.NETCore.App]

Microsoft.NETCore.App 7.0.10 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.15 C:\Program Files\dotnet\shared[Microsoft.WindowsDesktop.App]

Microsoft.WindowsDesktop.App 6.0.21 C:\Program Files\dotnet\shared[Microsoft.WindowsDesktop.App]

Microsoft.WindowsDesktop.App 7.0.10 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

Learn more:

https://aka.ms/dotnet/info

Download .NET:

https://aka.ms/dotnet/download

Visual Studio Version

VS 2022 Pro

Additional context

No response

@krjone01 krjone01 changed the title Condition on csproj ItemGroup item removes entire line from ouput Condition on csproj ItemGroup item removes entire line from output Sep 11, 2023
@krjone01
Copy link
Author

Reposted to dotnet/sdk repo. New Bug Report

Closing here.

@KalleOlaviNiemitalo
Copy link

Perhaps this documentation helps: Ignore conditions expressions in MSBuild files
I have not tried it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants