modelsbuilder / ModelsBuilder.Original

The Community Models Builder for Umbraco
MIT License
114 stars 49 forks source link

Error generating models when a solution file contains solution folders #49

Closed danlister closed 9 years ago

danlister commented 9 years ago

After upgrading to v2.1.2 from v2.1.1, the ModelsBuilder VSIX is now unable to generate models when a solution file contains solution folders. After looking at the code, I can see that the way projects are iterated through has changed. The following line, specifically the reference to dte.Solution.Projects, loops through every kind of project file. This includes solution folders.

var vsProject = dte.Solution.Projects
    .Cast<EnvDTE.Project>()
    .Select(ToHierarchy)
    .Cast<IVsProject>()
    .FirstOrDefault(x =>
    {
        int iFound;
        x.IsDocumentInProject(inputFilePath, out iFound, pdwPriority, out itemId);
        return iFound != 0 && itemId != 0;
    });

The exception actually occurs on the following line, as when selecting each project via the ToHierarchy() method, solution folders have no file name.

using (var projectReader = XmlReader.Create(project.FileName))

A couple of fixes could be applied. The code could either select projects that do not match the solution folder type guid or a defensive code check could be added to ToHierarchy() to make sure we have something within the FileName property.

zpqrtbnk commented 9 years ago

Have merged the PR, and will release a new version in a few days. Excellent work & MANY THANKS!

danlister commented 9 years ago

@zpqrtbnk No problem at all. Thanks for creating an awesome package :)

Mesomorf commented 9 years ago

Hi. It seems like I still have this problem. I have installed the following 1) Umbraco ModelsBuilder Custom Tool v.2.1.3.43 in VS. 2) Zbu.ModelsBuilder.AspNet v.2.1.3-beta001 3) Zbu.ModelsBuilder v.2.1.3-beta001

If the assembly where i'm using the Builder.cs is inside a solution folder, the builder does not work ( ZbuModelsBuilder failed to generate code: Exception: Panic: source file not found in any project.).

If I move the assembly outside the solution folder every thing works fine.

danlister commented 9 years ago

Hey @Mesomorf. The extension requires a project file in order to build your models correctly. Is there a reason why your Builder.cs class lives in a Solution Folder? How would you have previously used your generated models if they did not reside within a compilable project? Thanks, Dan.

Mesomorf commented 9 years ago

Hi danlister

Maybe I haven't clean how my solution structure is.

in this solution structure does the builder not work

but in this structure it works.

zpqrtbnk commented 9 years ago

Are we talking about Windows filesystem folder, ie real folders that you can see in the file explorer, or Visual Studio folders, ie the structure you see in the solution explorer? Also - any chance you can share with me (email) a ZIP of the entire structure that is not working?

Mesomorf commented 9 years ago

I Hope this work. You should be able to download a zip file here.

https://drive.google.com/folderview?id=0B1CBt4c9wS3zOHNkNjdIQXdnRUU&usp=sharing

Fra: Stephan [mailto:notifications@github.com] Sendt: 13. juni 2015 18:55 Til: zpqrtbnk/Zbu.ModelsBuilder Cc: Mesomorf Emne: Re: [Zbu.ModelsBuilder] Error generating models when a solution file contains solution folders (#49)

Are we talking about Windows filesystem folder, ie real folders that you can see in the file explorer, or Visual Studio folders, ie the structure you see in the solution explorer? Also - any chance you can share with me (email) a ZIP of the entire structure that is not working?

— Reply to this email directly or view it on GitHub https://github.com/zpqrtbnk/Zbu.ModelsBuilder/issues/49#issuecomment-111729519 . https://github.com/notifications/beacon/AA2gNe5V8uExeW_SIW-QusnZicQEjrqNks5oTFfpgaJpZM4EacqG.gif

zpqrtbnk commented 9 years ago

OK, I have downloaded the solution. Now I see: you have some projects within a Visual Studio "Solution Folder". Unfortunately, that is not supported at the moment.

Some background: when the custom tool runs, it needs to go through the entire solution to locate the Visual Studio "internal" object corresponding to the file that supports the custom tool (eg builder.cs or generator.cs). Originally, we would look at any root project in the solution, but that would fail with some types of projects such as web apps, and... solution folders. So for the time being, these two types of projects are skipped/ignored.

In order to deal with your solution, the processing code needs to be refactored. I have created this issue to take care of it when possible. And of course... the code is open, so if anyone feels like having a look at it... that'd be great!

Mesomorf commented 9 years ago

Thanks for the help.

zpqrtbnk commented 9 years ago

beta008 is now out and should fix most of these issues including projects in solution folders. would be great if you all could test. thanks!

Mesomorf commented 9 years ago

Sure I’ll test it. Is there a version on nuGet or do I get the source code?

Fra: Stephan [mailto:notifications@github.com] Sendt: 18. juni 2015 14:16 Til: zpqrtbnk/Zbu.ModelsBuilder Cc: Mesomorf Emne: Re: [Zbu.ModelsBuilder] Error generating models when a solution file contains solution folders (#49)

beta008 is now out and should fix most of these issues including projects in solution folders. would be great if you all could test. thanks!

— Reply to this email directly or view it on GitHub https://github.com/zpqrtbnk/Zbu.ModelsBuilder/issues/49#issuecomment-113134691 . https://github.com/notifications/beacon/AA2gNdzgJKwDHhocwz_u6kV0DMrdcFxvks5oUq3ngaJpZM4EacqG.gif

zpqrtbnk commented 9 years ago

beta008 does not change the site-hosted part, only the VSIX extension, which you can download on the release page.

Mesomorf commented 9 years ago

I’t seem like it have solved my problem. I have been moving my project around in the solution structure and the models are generated.

Fra: Stephan [mailto:notifications@github.com] Sendt: 19. juni 2015 08:12 Til: zpqrtbnk/Zbu.ModelsBuilder Cc: Mesomorf Emne: Re: [Zbu.ModelsBuilder] Error generating models when a solution file contains solution folders (#49)

beta008 does not change the site-hosted part, only the VSIX extension, which you can download on the release page https://github.com/zpqrtbnk/Zbu.ModelsBuilder/releases/tag/2.1.3-beta008 .

— Reply to this email directly or view it on GitHub https://github.com/zpqrtbnk/Zbu.ModelsBuilder/issues/49#issuecomment-113386886 .Billede fjernet af afsender.