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

Environment breaking ItemGroups added when I add, rename, or copy and paste files in solution explorer #7028

Closed
jons-aura opened this issue Mar 16, 2021 · 18 comments
Assignees
Labels
Triage-Investigate Reviewed and investigation needed by dev team
Milestone

Comments

@jons-aura
Copy link

Visual Studio Version:

16.8.4

Summary:

Same issue as here I think. #2810
I'm getting environment breaking ItemGroups added when I add, rename, or copy and paste files in solution explorer.

Steps to Reproduce:

  1. Rename a file in VS

  2. csproj gets updated

  3. VS freaks out and I have to remove the spurious csproj entries and entirely close and reopen VS

Expected Behavior:

csproj should not be updated.

Actual Behavior:

User Impact:

@jjmew
Copy link
Contributor

jjmew commented Mar 16, 2021

@jons-aura Is this on an SDK style project? can you send us the before and after csproj file?

@jons-aura
Copy link
Author

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <Nullable>warnings</Nullable>
    <TargetFramework>netstandard2.1</TargetFramework>
    <DebugType>Full</DebugType>
    <!--<Nullable>enable</Nullable>-->
    <!--<WarningsAsErrors>nullable</WarningsAsErrors>-->
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <WarningsAsErrors>;NU1605;CS0108</WarningsAsErrors>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="CsvHelper" Version="16.0.0" />
    <PackageReference Include="Hangfire.Core" Version="1.7.17" />
    <PackageReference Include="IronPdf" Version="2020.10.3.3" />
    <PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="5.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.OData" Version="7.5.2" />
    <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Options" Version="5.0.0" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
    <PackageReference Include="Sendgrid" Version="9.21.1" />
    <PackageReference Include="Serilog" Version="2.10.0" />
    <PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
    <PackageReference Include="System.DirectoryServices" Version="5.0.0" />
    <PackageReference Include="System.DirectoryServices.AccountManagement" Version="5.0.0" />
  </ItemGroup>
  
  <ItemGroup>
    <ProjectReference Include="XXXX" />
  </ItemGroup>

</Project>

becomes

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <Nullable>warnings</Nullable>
    <TargetFramework>netstandard2.1</TargetFramework>
    <DebugType>Full</DebugType>
    <!--<Nullable>enable</Nullable>-->
    <!--<WarningsAsErrors>nullable</WarningsAsErrors>-->
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <WarningsAsErrors>;NU1605;CS0108</WarningsAsErrors>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="Models\WebSpecialAssignmentDto - Copy.cs" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="CsvHelper" Version="16.0.0" />
    <PackageReference Include="Hangfire.Core" Version="1.7.17" />
    <PackageReference Include="IronPdf" Version="2020.10.3.3" />
    <PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="5.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.OData" Version="7.5.2" />
    <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Options" Version="5.0.0" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
    <PackageReference Include="Sendgrid" Version="9.21.1" />
    <PackageReference Include="Serilog" Version="2.10.0" />
    <PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
    <PackageReference Include="System.DirectoryServices" Version="5.0.0" />
    <PackageReference Include="System.DirectoryServices.AccountManagement" Version="5.0.0" />
  </ItemGroup>
  
  <ItemGroup>
    <ProjectReference Include="XXXX" />
  </ItemGroup>

</Project>

@drewnoakes
Copy link
Member

@jons-aura I agree that VS probably shouldn't be adding the Compile item to your project, but I cannot see how that would cause any actual problems.

VS freaks out and I have to remove the spurious csproj entries and entirely close and reopen VS

Can you be more specific about the problem so that we can further diagnose?

@jons-aura
Copy link
Author

I couldn't get it to "freak out" by copy+pasting but when I renamed a file in Solution Explorer it did.
image

As you can see the renamed file shows up as added and fine but every other file in the project now shows as not being part of the project. If I right click -> unload and then right click -> reload it doesn't help. If I edit the .csproj and remove the new "Compile" item and unload, reload that doesn't help either, I have to close and reopen VS entirely to get it to load correctly again.

@drewnoakes
Copy link
Member

@jons-aura if you're able to end up with a missing item (item with a red cross) by using copy/paste and rename in VS, then there is a bug. I've tried this out locally and couldn't get a repro. To understand what's happening we need a step-y-step breakdown, with some more screenshots at various points. I'm particularly concerned that there is a state for which restarting VS made a difference, but reloading the project did not. Can you provide steps to get into that state please? It would be ideal if you started with a blank project, so that we can rule out other customisations to the project.

@jons-aura
Copy link
Author

  • New project
  • Console Application
  • Target Framework .Net Core 5

image
image
image
Copied by CTRL-C CTRL-V
image
Renaming via F2
image
Solution Explorer immediately after rename
image
.csproj contents

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="Class1 - Copy.cs" />
    <Compile Include="Class1.cs" />
  </ItemGroup>

</Project>

@drewnoakes
Copy link
Member

@jons-aura thank you very much. That is perfect.

@ocallesp you were looking at rename operations recently. Does this look familiar?

@jjmew
Copy link
Contributor

jjmew commented Mar 23, 2021

@drewnoakes were you able to repro this? We tried it during triage and we couldn't repro it

@drewnoakes
Copy link
Member

I did not try to repro this.

Trying now in a newer build of VS I am not able to repro it.

@jons-aura are you able to upgrade to 16.9.x to see if the issue has been fixed?

@jons-aura
Copy link
Author

@drewnoakes I can still reproduce it with 16.9.2

@drewnoakes
Copy link
Member

@jons-aura do you have any extensions installed?

@jons-aura
Copy link
Author

@drewnoakes I couldn't find a quick way to get them via text but here's a screenshot of the list
image

@drewnoakes
Copy link
Member

If you run devenv.exe /SafeMode it'll launch without extensions. I'd be curious if that fixes the problem.

@jons-aura
Copy link
Author

@drewnoakes I can't open the solution in safe mode. The project shows as "needs migration" in Solution Explorer.

@drewnoakes
Copy link
Member

@jons-aura thank you for bringing that to our attention. I've filed this as a bug here #7046

In the meantime I'm perplexed as to what's causing this behaviour. Are you able to verify whether this occurs on another machine?

Does the error state eventually resolve itself, or does it remain with the red cross on the item indefinitely?

@jons-aura
Copy link
Author

I would have sworn I replied to this already. I spent some time removing extensions and seeing if the problem kept happening - so far it is - but I asked a coworker to try and reproduce it and they couldn't. I'll try to find some time to poke at this some more but if I don't reply in a week or two feel free to close this since it doesn't seem to be a common issue and it's mostly just annoying.

@drewnoakes
Copy link
Member

The fix for /SafeMode will be in 16.10 preview 2, so if you download that once it becomes available (soon I believe) then you could use that to exclude extensions from the picture.

Other things to look for on your machine:

  • The presence of an .editorconfig file somewhere in the ancestry of your project
  • The presence of Directory.Build.props or Directory.Build.targets files somewhere in the ancestry of your project

You could try copying your entire repository to another folder (e.g. C:\foo) then deleting all bin/obj/.vs folders. If you're using git, git clean -xdf can help.

@jjmew jjmew added the Triage-Investigate Reviewed and investigation needed by dev team label May 11, 2021
@jjmew jjmew added this to the Backlog milestone May 11, 2021
@jons-aura
Copy link
Author

I got a new system and reinstalled everything and can no longer reproduce this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Triage-Investigate Reviewed and investigation needed by dev team
Projects
None yet
Development

No branches or pull requests

3 participants