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

File linked to .NET core project gets removed from the project when the BuildAction is set to AdditionalFiles from None. #1149

Closed
aakash-johari opened this issue Jan 12, 2017 · 19 comments
Assignees
Labels
Area-External-CPS Owned by CPS and not this repo. Likely be closed in lieu of issue filed against VS platform. Bug This is a functional issue in already written code.
Milestone

Comments

@aakash-johari
Copy link

aakash-johari commented Jan 12, 2017

Scenario:

  1. Create a .NET core project and have a file linked to the project which has BuildAction=None.
  <ItemGroup>
    <None Include="..\abc\xyz.txt">
      <Link>xyz.txt</Link>
    </None>
  </ItemGroup>

Adding a link from Visual Studio 2017 doesn't seem to be possible. It makes a copy of the file in the project folder. So I edited the .csproj file. In our scenario we don't want to make duplicates of the file.

  1. From Visual Studio, change the BuildAction to AdditionalFiles. The file disappears from the project.

ConsoleApp1.csproj

@davkean
Copy link
Member

davkean commented Jan 12, 2017

@mavasani We added an additional files rule right? Did we also add it to the list of items that show up in the tree (itemSchemas)?

@aakash-johari When it disappears, do you mean the solution tree? Or do you mean that it's physically removed from the project file. Can you check the project file and see if it's present?

@mavasani
Copy link
Contributor

@davkean Yes, I verified additional files showed up in solution explorer after changing the build action. Let me attempt to repro @aakash-johari scenario on latest build.

@mavasani mavasani self-assigned this Jan 12, 2017
@davkean
Copy link
Member

davkean commented Jan 12, 2017

Yeah, what is the that <ContentType> thing you don't have one for AdditionalFiles, and where are the other content types? Perhaps we're inheriting them from MSBuild common targets./

@mavasani
Copy link
Contributor

@davkean
Copy link
Member

davkean commented Jan 12, 2017

It looks like <ContentType/> refers to the ItemType - perhaps that is needed?

@mavasani
Copy link
Contributor

Ok, so I investigated further and this seems unrelated to AdditionalFiles, but is instead specific to linked files.

  1. This issue does not repro if xyz.txt is just a regular file in the project tree with build action None.
  2. This issue repros even if step 2 is changed so the new build action is something else (content, embedded resource, etc.)

@mavasani
Copy link
Contributor

So, I am seeing something weird happening here:

  1. After the above repro steps, if I open the csproj on the disk, it still has the old ItemGroup with build action None.
  2. If I invoke "Edit .csproj", then the item group doesn't show up in the csproj opened from the temp location.

Even clicking save all doesn't change the contents of csproj on the disk, it still has the old item group.

@mavasani mavasani removed their assignment Jan 13, 2017
@aakash-johari
Copy link
Author

aakash-johari commented Jan 13, 2017

@davkean Yes the file is removed from the project file and hence no longer visible in the solution tree as well. I have updated the bug description with the .csproj file I used. I opened that project file in visual studio and changed the build action of the abc.xyz to AdditionalFiles. The file abc.xyz disappeared from the solution tree and even the entry from the .csproj file was removed.

And if you think that the given .csproj file has the link entry wrong, it has been generated after following code executes in our extension -
dteProject.ProjectItems.AddFromFile(filePath);

And the file disappears after we change the type to AdditionalFiles, manually or by following code in our extension -
item.Properties.Item("ItemType").Value = “AdditionalFiles”;

@davkean
Copy link
Member

davkean commented Jan 20, 2017

@mavasani What's happening with this? Is this our bug or CPS?

@davkean davkean added the Bug This is a functional issue in already written code. label Jan 20, 2017
@davkean davkean added this to the 1.0 RTM milestone Jan 20, 2017
@mavasani
Copy link
Contributor

mavasani commented Jan 20, 2017

I debugged this further and it looks like a CPS issue. We have correct old and new types inside ProjectItemProviderBase.OnItemIdentityChangedAsync and also invoke SourceItemsProvider_ItemsRemoved for the old item and SourceItemsProvider_ItemsAdded for the new item, but somehow only remove seems to be working and we never add back the new project item.

@mavasani
Copy link
Contributor

I have ported this issue to CPS bug 371345: Changing the BuildAction within VS for a linked file which lies outside the project cone causes the item to disappear from the project file.

@mavasani
Copy link
Contributor

Also tagging @lifengl and @jviau as an FYI

@mavasani mavasani added the Area-External-CPS Owned by CPS and not this repo. Likely be closed in lieu of issue filed against VS platform. label Jan 20, 2017
@jviau
Copy link
Contributor

jviau commented Jan 21, 2017

I found the cause in CPS and am working on a fix. However, I found a bigger issue with msbuild: dotnet/msbuild#1598

Items outside the project cone are being matched to globs inside the project cone when using GetItemProvenance. This means in this case, you cannot change the build action from Content back to Compile. We will match to the **/*.cs glob, consider it included, and fail.

@cdmihai suggested a workaround for now by changing the glob to $(MSBuildProjectDirectory)/**/*.cs.

@aakash-johari
Copy link
Author

@mavasani @jviau Is this intentional to make a copy of the linked file? Making a copy doesn't seem right. It fails the basic idea of links where using a link to a file one could update the original file.

@davkean
Copy link
Member

davkean commented Jan 23, 2017

@aakash-johari What's the repro for making a copy of the linked file?

@aakash-johari
Copy link
Author

@davkean

  1. Create a .NET core project.
  2. Right click the project, choose "Add" and "Existing Item..."
  3. Select a file that is not under the project folder.
  4. You'll see a copy of the file in the folder where your .csproj file is present. i.e. your project folder.

@davkean
Copy link
Member

davkean commented Jan 23, 2017

That's not linking a item, that's adding a item. To link, you need to click the arrow next to the Add button and choose "add as link".

ie While surprising behavior - that's how it's worked for ~15 years.

@aakash-johari
Copy link
Author

Oh. My bad then. :( I didn't know about "Add as link". Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-External-CPS Owned by CPS and not this repo. Likely be closed in lieu of issue filed against VS platform. Bug This is a functional issue in already written code.
Projects
None yet
Development

No branches or pull requests

4 participants