Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

T4 VS Project Integration Error #77

Closed
dcastenholz opened this issue May 29, 2019 · 6 comments
Closed

T4 VS Project Integration Error #77

dcastenholz opened this issue May 29, 2019 · 6 comments
Labels
bug Confirmed bug released Issue is resolved in a current release

Comments

@dcastenholz
Copy link
Contributor

When nested folders are specified for the targets of the t4 generated files, the top level folder will be created, but if there are multiple sub folders under the main folder, only the first one will be created. This results in the newly generated files being added to the VS project under the xxx.tt template file.

Found the cause in MultipleOutputHelper.ttinclude. Initialization of bool found = false; is in the wrong place.

Please change:

      private ProjectItem GetOrCreateParentItem(string filePath)
      {
         if (string.IsNullOrEmpty(filePath))
            return templateProjectItem;

         string projectDirectory = Path.GetDirectoryName(templateProjectItem.ContainingProject.FullName);
         string fileDirectory = Path.GetDirectoryName(filePath);

         if (fileDirectory.ToLower() == projectDirectory.ToLower())
            return templateProjectItem;

         ProjectItem result = templateProjectItem;

         string relativeFilePath = fileDirectory.Substring(projectDirectory.Length + 1);
         Queue<string> pathParts = new Queue<string>(relativeFilePath.Split('\\'));
         ProjectItems currentItemList = templateProjectItem.ContainingProject.ProjectItems;
=>       bool found = false;

         while (pathParts.Any())
         {
                  string pathPart = pathParts.Dequeue();
...

To:

      private ProjectItem GetOrCreateParentItem(string filePath)
      {
         if (string.IsNullOrEmpty(filePath))
            return templateProjectItem;

         string projectDirectory = Path.GetDirectoryName(templateProjectItem.ContainingProject.FullName);
         string fileDirectory = Path.GetDirectoryName(filePath);

         if (fileDirectory.ToLower() == projectDirectory.ToLower())
            return templateProjectItem;

         ProjectItem result = templateProjectItem;

         string relativeFilePath = fileDirectory.Substring(projectDirectory.Length + 1);
         Queue<string> pathParts = new Queue<string>(relativeFilePath.Split('\\'));
         ProjectItems currentItemList = templateProjectItem.ContainingProject.ProjectItems;

         while (pathParts.Any())
         {
=>                bool found = false;
                  string pathPart = pathParts.Dequeue();
...
@dcastenholz
Copy link
Contributor Author

Note that this bug only occurs on the initial creation of the generated files that are in nested folders. Once the folders are already added, the existing project integration works as designed. The above code fix will correct the initial folder additions to the VS project.
To test for the bug, create multiple files in a folder like Generated\Folder1\Folder2.

@msawczyn
Copy link
Owner

msawczyn commented Jun 4, 2019

Odd. You shouldn't be able to pick project folders that don't exist. How are you specifying those?

@dcastenholz
Copy link
Contributor Author

They were initially created and then selected i the UI, but then I sometimes like to delete the whole Generated folder tree for a clean build.

@msawczyn
Copy link
Owner

msawczyn commented Jun 7, 2019

Aha! A loophole, eh? Fair enough... :-)

@msawczyn msawczyn added the bug Confirmed bug label Jun 7, 2019
@msawczyn
Copy link
Owner

msawczyn commented Jul 9, 2019

Fixed in v1.3.0.4

@msawczyn msawczyn added pending release Issue is resolved in the current codebase, will be published with the next release released Issue is resolved in a current release and removed pending release Issue is resolved in the current codebase, will be published with the next release labels Jul 9, 2019
@msawczyn
Copy link
Owner

Closing since fix was released.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Confirmed bug released Issue is resolved in a current release
Projects
None yet
Development

No branches or pull requests

2 participants