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

VS automatically adds <ItemGroup> with Remove="xxx" for new files #8636

Closed
tompazourek opened this issue Oct 24, 2022 · 3 comments
Closed

VS automatically adds <ItemGroup> with Remove="xxx" for new files #8636

tompazourek opened this issue Oct 24, 2022 · 3 comments

Comments

@tompazourek
Copy link

Visual Studio Version

17.3.6

Summary

I have a custom package that automatically adds all CSHTML files inside a project into a custom MSBuild item called <RazorTranspilerInputRazor> used by some tooling we have. The MSBuild code looks inside the package looks as follows:

<ItemGroup>
  <RazorTranspilerInputRazor Include="**\*.cshtml" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
</ItemGroup>

When I then add a new CSHTML file in Visual Studio in Solution explorer (I usually copy-paste an existing one), Visual Studio adds some custom code to explicitly remove the new file from the wildcard... Let's assume I create a copy of file XXX.cshtml This is what gets automatically appended to the csproj by Visual Studio:

<ItemGroup>
  <RazorTranspilerInputRazor Remove="XXX.cshtml" />
</ItemGroup>

How do I stop this behavior? I want the original wildcard to work and include all CSHTML files, including the new files. Yet, Visual Studio tries very hard to break this and exclude any new files from the wildcard. Every time I copy-paste a file, VS removes it, and I have to revert that removal. It's very annoying.

Is there some way to work around this?

I found some other people having similar issues, e.g.: https://stackoverflow.com/questions/69240061/how-to-stop-visual-studio-from-automatically-adding-remove-in-an-item-group-in-m But no answer yet.

@tompazourek
Copy link
Author

Related: dotnet/aspnetcore#27718

@tompazourek
Copy link
Author

I found a possible workaround for me. Since I don't need the item in design-time, making the wildcard include conditional seems to fix the issue:

<ItemGroup Condition="'$(DesignTimeBuild)' != 'true'">
  <RazorTranspilerInputRazor Include="**\*.cshtml" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
</ItemGroup>

Still, this is very annoying, and I'm not sure how I'd fix the issue if I needed the MSBuild items even in design-time...

@adamint
Copy link
Member

adamint commented Oct 27, 2022

Hi @tompazourek, can you open a feedback ticket at https://developercommunity.visualstudio.com/home or through Visual Studio with "Help | Send Feedback | Report a Problem..." and put the link here so we can ensure it's routed correctly? We believe this is a CPS issue.

@adamint adamint closed this as completed Oct 27, 2022
bantolov added a commit to Rhetos/Rhetos that referenced this issue Nov 8, 2022
…tead of .targets, in order to allow customization in Rhetos app's .csproj file." This reverts commit c91a531.

This feature was causing the following issue: When adding a new file to the project, Visual Studio automatically marked the file as removed from RhetosBuild ItemGroup in csproj file. See dotnet/aspnetcore#27718, dotnet/project-system#8636
bantolov added a commit to Rhetos/AfterDeploy that referenced this issue Nov 8, 2022
…tead of .targets, in order to allow customization in Rhetos app's .csproj file." This reverts commit 9988d9f.

This feature was causing the following issue: When adding a new file to the project, Visual Studio automatically marked the file as removed from RhetosBuild ItemGroup in csproj file. See dotnet/aspnetcore#27718, dotnet/project-system#8636
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