microsoft / VSProjectSystem

Documentation for extending Visual Studio with new types of projects.
Other
314 stars 88 forks source link

Improve Logging - ProjectTreeCorruptionException on project create with template #196

Open dazinator opened 7 years ago

dazinator commented 7 years ago

in my vstemplate file, for my project template, I decided to add an extra item:

 <TemplateContent>
    <Project File="DnnProjectSystem.dnnproj" ReplaceParameters="true">
      <!-- 
      These are the items which will show up when a new project is created using the custom project system.
      Items referenced in here must also be referenced in the project file.
      -->
      <ProjectItem>Properties\AssemblyInfo.cs</ProjectItem>
      <ProjectItem ItemType="DnnManifest">manifest.dnn</ProjectItem>

      <!--<ProjectItem OpenInEditor="true" ReplaceParameters="true">Program.cs</ProjectItem>-->
    </Project>

In ProjectItemsSchema.xaml

<ContentType
        Name="DnnManifest"
        DisplayName="Dnn Manifest"
        ItemType="DnnManifest">
    </ContentType>

 <ItemType Name="DnnManifest" DisplayName="Dnn Package Manifest" />

  <FileExtension Name=".dnn" ContentType="DnnManifest"/>

and the rule:

<Rule
    Name="DnnManifest"
    DisplayName="DnnManifest"
    PageTemplate="tool"
    Description="DnnManifest build items"
    xmlns="http://schemas.microsoft.com/build/2009/properties">
    <Rule.DataSource>
        <DataSource Persistence="ProjectFile" HasConfigurationCondition="True" ItemType="DnnManifest" />
    </Rule.DataSource>

    <StringProperty Name="MyProperty" DisplayName="My Property" Visible="True" Description="Sample property"/>

    <StringProperty Name="Identity" DisplayName="File Name" ReadOnly="true" Category="Misc">
        <StringProperty.DataSource>
            <DataSource Persistence="Intrinsic" ItemType="DnnManifestCompile" PersistedName="Identity" />
        </StringProperty.DataSource>
    </StringProperty>

    <StringProperty Name="FullPath" DisplayName="Full Path" ReadOnly="true" Category="Misc">
        <StringProperty.DataSource>
            <DataSource Persistence="Intrinsic" ItemType="DnnManifestCompile" PersistedName="FullPath" />
        </StringProperty.DataSource>
    </StringProperty>

    <BoolProperty Name="Visible" Visible="False" />
    <StringProperty Name="DependentUpon" Visible="false" />
    <StringProperty Name="Link" Visible="false" />
</Rule>

This rule is included in my custom targets file:

 <PropertyPageSchema Include="$(MSBuildThisFileDirectory)Rules\DnnManifest.xaml;">
      <Context>File;BrowseObject;</Context>
    </PropertyPageSchema>

In my project template, in the project file:

<ItemGroup>
    <DnnManifest Include="manifest.dnn"></DnnManifest>
  </ItemGroup>

The idea being that when the project is created, the "manifest.dnn" file will automatically be included in the project, with a "DnnManifest" item type.

However one important point, is that my custom project targets are added via a nuget install step in the vstemplate:


<WizardExtension>
    <Assembly>NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly>
    <FullClassName>NuGet.VisualStudio.TemplateWizard</FullClassName>
  </WizardExtension>
  <WizardData>
    <packages repository="extension"
          repositoryId="DnnProjectSystem.ProjectType..d310c2e3-dc4e-4aab-95cd-f70cba3ecd6f">
      <package id="DnnProjectSystem.BuildTools" version="0.0.1-alpha1" />
      <!--<package id="DnnPackager" version="2.0.6" />-->
    </packages>
  </WizardData>

The issue is, when I create the project, the manifest file is not added, and I get an error window displayed, saying an error was logged. Looking at the log I see this:

===================
26/02/2017 17:17:09
Recoverable
System.AggregateException: One or more errors occurred. ---> Microsoft.VisualStudio.ProjectSystem.ProjectTreeCorruptionException: Failed to update the project tree. ---> System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
   at System.Collections.Immutable.ImmutableDictionary`2.get_Item(TKey key)
   at Microsoft.VisualStudio.ProjectSystem.Designers.PhysicalProjectTreeProvider.HandleRenamedItems(IProjectTree tree, IImmutableDictionary`2 changeMap, IProjectChangeDescription change, IImmutableDictionary`2 projectData, HashSet`1 dynamicDependentChildrenAffected, ConfiguredProjectExports configuredProjectExports)
   at Microsoft.VisualStudio.ProjectSystem.Designers.PhysicalProjectTreeProvider.OnProjectSubscriptionChanged(IProjectTree originalTree, ConfiguredProjectExports configuredProjectExports, PhysicalProjectTreeInputData updateInput, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at Microsoft.VisualStudio.ProjectSystem.Designers.PhysicalProjectTreeProvider.OnProjectSubscriptionChanged(IProjectTree originalTree, ConfiguredProjectExports configuredProjectExports, PhysicalProjectTreeInputData updateInput, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.ProjectSystem.Designers.PhysicalProjectTreeProvider.<>c__DisplayClass172_0.<ProjectSubscriptionService_ChangedAsync>b__0(IProjectVersionedValue`1 treeSnapshot, ConfiguredProjectExports configuredProjectExports, CancellationToken ct)
   at Microsoft.VisualStudio.ProjectSystem.ProjectTreeProviderBase.TreeUpdateSubmission.<UpdateTree>d__25.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.ProjectTreeProviderBase.<>c__DisplayClass95_0.<<Initialize>b__1>d.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.ProjectTreeProviderBase.<>c__DisplayClass102_0.<<SubmitTreeUpdateAsync>b__0>d.MoveNext()
   --- End of inner exception stack trace ---
---> (Inner Exception #0) Microsoft.VisualStudio.ProjectSystem.ProjectTreeCorruptionException: Failed to update the project tree. ---> System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
   at System.Collections.Immutable.ImmutableDictionary`2.get_Item(TKey key)
   at Microsoft.VisualStudio.ProjectSystem.Designers.PhysicalProjectTreeProvider.HandleRenamedItems(IProjectTree tree, IImmutableDictionary`2 changeMap, IProjectChangeDescription change, IImmutableDictionary`2 projectData, HashSet`1 dynamicDependentChildrenAffected, ConfiguredProjectExports configuredProjectExports)
   at Microsoft.VisualStudio.ProjectSystem.Designers.PhysicalProjectTreeProvider.OnProjectSubscriptionChanged(IProjectTree originalTree, ConfiguredProjectExports configuredProjectExports, PhysicalProjectTreeInputData updateInput, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at Microsoft.VisualStudio.ProjectSystem.Designers.PhysicalProjectTreeProvider.OnProjectSubscriptionChanged(IProjectTree originalTree, ConfiguredProjectExports configuredProjectExports, PhysicalProjectTreeInputData updateInput, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.ProjectSystem.Designers.PhysicalProjectTreeProvider.<>c__DisplayClass172_0.<ProjectSubscriptionService_ChangedAsync>b__0(IProjectVersionedValue`1 treeSnapshot, ConfiguredProjectExports configuredProjectExports, CancellationToken ct)
   at Microsoft.VisualStudio.ProjectSystem.ProjectTreeProviderBase.TreeUpdateSubmission.<UpdateTree>d__25.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.ProjectTreeProviderBase.<>c__DisplayClass95_0.<<Initialize>b__1>d.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.ProjectTreeProviderBase.<>c__DisplayClass102_0.<<SubmitTreeUpdateAsync>b__0>d.MoveNext()
Project: c:\users\darrell\documents\visual studio 2017\Projects\DnnExtension87\DnnExtension87\DnnExtension87.dnnproj
PRIOR tree: 
DnnExtension87 (visibility: visible, capabilities: {ProjectRoot}), FilePath: ""
    bin (visibility: invisible, capabilities: {FileSystemEntity Folder IncludeInProjectCandidate VisibleOnlyInShowAllFiles}), FilePath: "c:\users\darrell\documents\visual studio 2017\Projects\DnnExtension87\DnnExtension87\bin\"
        Debug (visibility: visible, capabilities: {FileSystemEntity Folder IncludeInProjectCandidate}), FilePath: "c:\users\darrell\documents\visual studio 2017\Projects\DnnExtension87\DnnExtension87\bin\Debug\"
    obj (visibility: invisible, capabilities: {FileSystemEntity Folder IncludeInProjectCandidate VisibleOnlyInShowAllFiles}), FilePath: "c:\users\darrell\documents\visual studio 2017\Projects\DnnExtension87\DnnExtension87\obj\"
        Debug (visibility: visible, capabilities: {FileSystemEntity Folder IncludeInProjectCandidate}), FilePath: "c:\users\darrell\documents\visual studio 2017\Projects\DnnExtension87\DnnExtension87\obj\Debug\"
            CoreCompileInputs.cache (visibility: visible, capabilities: {FileOnDisk FileSystemEntity IncludeInProjectCandidate}), FilePath: "c:\users\darrell\documents\visual studio 2017\Projects\DnnExtension87\DnnExtension87\obj\Debug\CoreCompileInputs.cache"
    Properties (visibility: visible, capabilities: {FileSystemEntity Folder}), FilePath: "c:\users\darrell\documents\visual studio 2017\Projects\DnnExtension87\DnnExtension87\Properties\"
        AssemblyInfo.cs (visibility: visible, capabilities: {FileOnDisk FileSystemEntity SourceFile}), FilePath: "c:\users\darrell\documents\visual studio 2017\Projects\DnnExtension87\DnnExtension87\Properties\AssemblyInfo.cs"
    DnnExtension87.dnnproj (visibility: invisible, capabilities: {AlwaysInvisible FileOnDisk FileSystemEntity HiddenProjectSettingsFile IncludeInProjectCandidate}), FilePath: "c:\users\darrell\documents\visual studio 2017\Projects\DnnExtension87\DnnExtension87\DnnExtension87.dnnproj"
    packages.config (visibility: visible, capabilities: {FileOnDisk FileSystemEntity SourceFile}), FilePath: "c:\users\darrell\documents\visual studio 2017\Projects\DnnExtension87\DnnExtension87\packages.config"
    readme.txt (visibility: visible, capabilities: {FileOnDisk FileSystemEntity SourceFile}), FilePath: "c:\users\darrell\documents\visual studio 2017\Projects\DnnExtension87\DnnExtension87\readme.txt"
ACTUAL tree: 
DnnExtension87 (visibility: visible, capabilities: {ProjectRoot}), FilePath: ""
    bin (visibility: invisible, capabilities: {FileSystemEntity Folder IncludeInProjectCandidate VisibleOnlyInShowAllFiles}), FilePath: "c:\users\darrell\documents\visual studio 2017\Projects\DnnExtension87\DnnExtension87\bin\"
        Debug (visibility: visible, capabilities: {FileSystemEntity Folder IncludeInProjectCandidate}), FilePath: "c:\users\darrell\documents\visual studio 2017\Projects\DnnExtension87\DnnExtension87\bin\Debug\"
    obj (visibility: invisible, capabilities: {FileSystemEntity Folder IncludeInProjectCandidate VisibleOnlyInShowAllFiles}), FilePath: "c:\users\darrell\documents\visual studio 2017\Projects\DnnExtension87\DnnExtension87\obj\"
        Debug (visibility: visible, capabilities: {FileSystemEntity Folder IncludeInProjectCandidate}), FilePath: "c:\users\darrell\documents\visual studio 2017\Projects\DnnExtension87\DnnExtension87\obj\Debug\"
            CoreCompileInputs.cache (visibility: visible, capabilities: {FileOnDisk FileSystemEntity IncludeInProjectCandidate}), FilePath: "c:\users\darrell\documents\visual studio 2017\Projects\DnnExtension87\DnnExtension87\obj\Debug\CoreCompileInputs.cache"
    Properties (visibility: visible, capabilities: {FileSystemEntity Folder}), FilePath: "c:\users\darrell\documents\visual studio 2017\Projects\DnnExtension87\DnnExtension87\Properties\"
        AssemblyInfo.cs (visibility: visible, capabilities: {FileOnDisk FileSystemEntity SourceFile}), FilePath: "c:\users\darrell\documents\visual studio 2017\Projects\DnnExtension87\DnnExtension87\Properties\AssemblyInfo.cs"
    DnnExtension87.dnnproj (visibility: invisible, capabilities: {AlwaysInvisible FileOnDisk FileSystemEntity HiddenProjectSettingsFile IncludeInProjectCandidate}), FilePath: "c:\users\darrell\documents\visual studio 2017\Projects\DnnExtension87\DnnExtension87\DnnExtension87.dnnproj"
    packages.config (visibility: visible, capabilities: {FileOnDisk FileSystemEntity SourceFile}), FilePath: "c:\users\darrell\documents\visual studio 2017\Projects\DnnExtension87\DnnExtension87\packages.config"
    readme.txt (visibility: visible, capabilities: {FileOnDisk FileSystemEntity SourceFile}), FilePath: "c:\users\darrell\documents\visual studio 2017\Projects\DnnExtension87\DnnExtension87\readme.txt"
Inner exception:
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
   at System.Collections.Immutable.ImmutableDictionary`2.get_Item(TKey key)
   at Microsoft.VisualStudio.ProjectSystem.Designers.PhysicalProjectTreeProvider.HandleRenamedItems(IProjectTree tree, IImmutableDictionary`2 changeMap, IProjectChangeDescription change, IImmutableDictionary`2 projectData, HashSet`1 dynamicDependentChildrenAffected, ConfiguredProjectExports configuredProjectExports)
   at Microsoft.VisualStudio.ProjectSystem.Designers.PhysicalProjectTreeProvider.OnProjectSubscriptionChanged(IProjectTree originalTree, ConfiguredProjectExports configuredProjectExports, PhysicalProjectTreeInputData updateInput, CancellationToken cancellationToken)
<---

~I am wondering, could it be that at project creation time, as my targets are being installed via nuget, could it be that VS can't add the file because the item type isn't known yet? I am clutching at straws here.~ After i tidied up my rule file (some of the properties were tied to an invalid ItemType.), in combination with not using the same value for the ItemType name and the ContentType name (I now use DnnManifest for the content type, and DnnManifestFile for the ItemType - this exception goes away.

Leaving this issue open because I think a more helpful exception message would be in order here, i.e what is the key that couldn't be added?)

adrianvmsft commented 7 years ago

I am glad that you managed to find a way to avoid the problem. I agree, improving logging could make help investigate such issues. Renaming the issue to reflect that.