Repository navigation
Description
Repro steps
- Create new F# Console App (.NET Core) Project in Visual Studio
- Using the solution explorer, add a new folder in the project called "data"
- Then add a new file to that folder called "data.txt"
- Unload and modify the .fsproj file so that the following line:
<Content Include="data\data.txt" />
is replaced with:
<Content Include="data\*.txt" />
- Reload the project and try add a new file to the data directory
Alternative repro steps
- Clone my repo
- Open the .sln in Visual Studio
- Try add a new file to the input_files/2017 directory.
Expected behavior
The new file gets added to the project, but does not cause any modifications to the .fsproj file as it is already covered by the Content Include
Actual behavior
A recoverable exception is thrown causing the data folder to disappear from the project including the removal of the Content Include from the fsproj file. The stacktrace of the exception is as follows:
=====================
6/12/2018 7:50:56 PM
Recoverable
System.AggregateException: One or more errors occurred. ---> System.InvalidOperationException: The reference node is not a child of this node.
at Microsoft.Build.Shared.ErrorUtilities.ThrowInvalidOperation(String resourceName, Object[] args)
at Microsoft.Build.Construction.ProjectElementContainer.VerifyForInsertBeforeAfterFirst(ProjectElement child, ProjectElement reference)
at Microsoft.Build.Construction.ProjectElementContainer.InsertBeforeChild(ProjectElement child, ProjectElement reference)
at Microsoft.VisualStudio.ProjectSystem.VS.Input.Commands.Ordering.OrderingHelper.TryMoveElements(ImmutableArray`1 elements, ProjectItemElement referenceElement, MoveAction moveAction)
at Microsoft.VisualStudio.ProjectSystem.VS.Input.Commands.Ordering.OrderingHelper.TryMoveElementsToTop(Project project, ImmutableArray`1 elements, IProjectTree target)
at Microsoft.VisualStudio.ProjectSystem.VS.Input.Commands.Ordering.OrderingHelper.<>c__DisplayClass0_0.<Move>b__0(Project project)
at Microsoft.VisualStudio.ProjectSystem.ProjectAccessor.<OpenProjectForWriteAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.ProjectSystem.VS.Input.Commands.Ordering.OrderAddItemHintReceiver.<HintedAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Microsoft.VisualStudio.ProjectSystem.Designers.ProjectChangeHintSubmissionService.<>c__DisplayClass42_0.<<ProjectLockService_ReleasedWriteLockAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.VisualStudio.ProjectSystem.CommonProjectSystemTools.Rethrow(Exception ex)
at Microsoft.VisualStudio.ProjectSystem.ProjectErrorReporting.<>c__DisplayClass6_0.<SubmitErrorReport>b__0()
at Microsoft.VisualStudio.ProjectSystem.ExceptionFilter.<>c__DisplayClass2_0.<Guard>g__action|0()
at GuardMethodClass.GuardMethod(Func`1 , Func`2 , Func`2 )
--- End of inner exception stack trace ---
---> (Inner Exception #0) System.InvalidOperationException: The reference node is not a child of this node.
at Microsoft.Build.Shared.ErrorUtilities.ThrowInvalidOperation(String resourceName, Object[] args)
at Microsoft.Build.Construction.ProjectElementContainer.VerifyForInsertBeforeAfterFirst(ProjectElement child, ProjectElement reference)
at Microsoft.Build.Construction.ProjectElementContainer.InsertBeforeChild(ProjectElement child, ProjectElement reference)
at Microsoft.VisualStudio.ProjectSystem.VS.Input.Commands.Ordering.OrderingHelper.TryMoveElements(ImmutableArray`1 elements, ProjectItemElement referenceElement, MoveAction moveAction)
at Microsoft.VisualStudio.ProjectSystem.VS.Input.Commands.Ordering.OrderingHelper.TryMoveElementsToTop(Project project, ImmutableArray`1 elements, IProjectTree target)
at Microsoft.VisualStudio.ProjectSystem.VS.Input.Commands.Ordering.OrderingHelper.<>c__DisplayClass0_0.<Move>b__0(Project project)
at Microsoft.VisualStudio.ProjectSystem.ProjectAccessor.<OpenProjectForWriteAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.ProjectSystem.VS.Input.Commands.Ordering.OrderAddItemHintReceiver.<HintedAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Microsoft.VisualStudio.ProjectSystem.Designers.ProjectChangeHintSubmissionService.<>c__DisplayClass42_0.<<ProjectLockService_ReleasedWriteLockAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.VisualStudio.ProjectSystem.CommonProjectSystemTools.Rethrow(Exception ex)
at Microsoft.VisualStudio.ProjectSystem.ProjectErrorReporting.<>c__DisplayClass6_0.<SubmitErrorReport>b__0()
at Microsoft.VisualStudio.ProjectSystem.ExceptionFilter.<>c__DisplayClass2_0.<Guard>g__action|0()
at GuardMethodClass.GuardMethod(Func`1 , Func`2 , Func`2 )<---
===================
Known workarounds
I am able to resolve this by unloading the .fsproj file, readding the removed line, and loading again. Doing this shows the data folder with the original file and the file I attempted to create
Related information
- Operating system: Windows 17134.407
- Visual Studio: 15.9.3
- Visual F# Tools 10.2 for F# 4.5: 15.8.0.0. Commit Hash: 6e26c5b
- .NET Core 2.2
Note: I attempted to recreate this issue on a C# solution but wasn't able to since C# projects do not require a Content Include to be added to the .csproj file for the directory to be included in the project.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
cartermp commentedon Dec 6, 2018
Thanks @CameronAavik, this is related to file ordering. Looks like you've hit an edge case where you want to partially glob non-F# items under a specific folder. Not sure what the state of the world ought to be for F#, but @TIHan would know more.
TIHan commentedon Dec 6, 2018
The current state of the world is that we do not support globbing. However, I believe we should not be throwing an error.
If it is possible, it wouldn't be a bad idea to design globbing for files that are not important for file ordering and figure out how its interaction plays into file ordering
CameronAavik commentedon Dec 7, 2018
Yeah that makes sense for F# files. In my case I wish to use it as I have a number of resources in a directory that I want to have automatically copied to the output directory. I was hoping to make it so that if I add a new resource I don't have to add a new rule in to copy it to output every time. I can of course manually do that each time, but having it supported would be nice.
2 remaining items
marner2 commentedon May 27, 2021
Are there any updates on this? We're running into this issue as well with resource files that we want tracked with the project. This forces us to use another IDE (vscode) to manage those resources.
[-]Content Include removed from fsproj file after adding file to folder using VS Solution Explorer[/-][+]Globbing not supported for content in fsproj[/+]psfinaki commentedon Mar 27, 2024
The respective fix was reverted, see the comment here. This is essentially won't/can't fix now.