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

Adding item templates doesn't effect the project if EnableDefaultCompileItems is set to false. #1562

Closed
ericstj opened this issue Sep 5, 2017 · 6 comments
Labels
Milestone

Comments

@ericstj
Copy link
Member

ericstj commented Sep 5, 2017

Moved from dotnet/project-system#2678

Using 15.3 preview 26723.0.d15rel

  1. Create new NETStandard library project.
  2. Edit the CSproj to set EnableDefaultCompileItems and manually include class1.cs. EG:
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard1.4</TargetFramework>
    <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
  </PropertyGroup>

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

</Project>
  1. Do Add > New Item and select a class. Name it "test".
  2. In Class1.cs try to instantiate "test".

Expect: compile works and item is added to csproj.

Actual: added item is missing from project, but appears in the solution hierarchy 😕
Unloading and reloading the project maintains this state. The added item remains missing from the project file. I can't seem to do anything to get the file to disappear from the hierarchy.

@ericstj
Copy link
Member Author

ericstj commented Sep 5, 2017

from @davkean

//cc @lifengl @jviau

I spend some time thinking about this, and this behavior is by design.

First of all, to avoid this, opt out of the all the default globs by setting false property or opt just out of the default None glob by by setting false property.

The template has zero control over the item type here - it's solely gets added into whatever item type the project says it should. The same behavior occurs if you explicitly drop a new file on disk, or move it from one folder to another.

What's happening here is the project system to trying to avoid double-including the same file. It's seeing that adding this file would cause it to be covered by the None item and stops. It doesn't understand the complex rules in the SDK that says that adding a file to the Compile item would cause it to be removed from None item and hence avoid the double-include in this case.

It does this, because of these sorts of situations:

<Project>
  <ItemGroup>
    <None Include="*.cs" />
  </ItemGroup>
</Project>

If the project was to add the to the above, the file would now be included twice; once in None and once in Compile item.

Based on that, I'm going to resolve this by design.

@nguerrera
Copy link
Contributor

Note that #1157 is related. The requested behavior there is incompatible with the expectation expressed in dotnet/project-system#2678 (comment)
We should specify the correct behavior for .cs|.vb files that are not compiled. If we want them to continue to show in solution explorer as None items, then we should close #1157 and keep only this open.

Regardless, I think the fix for this issue we should be excluding @(Compile) from default @(None). Currently, we only exclude things that match the default compile glob, and only do so when default compile globbing is on. We probably also want to exclude the other well known items. E.g. Anything in @(EmbeddedResource) already should not be globbed in to @(None) either.

@lifengl
Copy link

lifengl commented Sep 13, 2017 via email

@davkean
Copy link
Member

davkean commented Sep 13, 2017

How do I disable all the default globbings, if I prefer to list all files by myself to reduce performance hit from globbings?

<EnableDefaultItems>false<EnableDefaultItems> property or opt just out of the default None glob by by setting <EnableDefaultNoneItems>false<EnableDefaultNoneItems> property.

@livarcocc livarcocc added this to the Unknown milestone Feb 12, 2018
JL03-Yue pushed a commit that referenced this issue Mar 19, 2024
[main] Update dependencies from dotnet/arcade


 - Update NuGet package version

 - Target tests at .NET 7 so they run on the appropriate runtime.

 - Update Versions.props

 - Move dotnet-format to .net7.0

 - Set eol for shell scripts

 - Make devcontainer user be root

 - Fix integration tests

 - Add local .dotnet folder to path during integration tests

 - Update path after restore

 - Use Net70 references in Analyzer tests
Copy link
Contributor

Due to lack of recent activity, this issue has been labeled as 'stale'. It will be closed if no further activity occurs within 30 more days. Any new comment will remove the label.

@github-actions github-actions bot added the stale label Apr 25, 2024
Copy link
Contributor

This issue will now be closed since it has been labeled 'stale' without activity for 30 days.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants