ormsolutions / NORMA

Core code for Natural Object-Role Modeling Architect, a Visual Studio extension for ORM modeling.
Other
42 stars 18 forks source link

The "New file" dialog does not create a new file #48

Open schelv opened 8 months ago

schelv commented 8 months ago

The "New file" dialog does not create a new .orm file.

Version information:

Microsoft Visual Studio Community 2022
Version 17.8.4
VisualStudio.17.Release/17.8.4+34408.163
Microsoft .NET Framework
Version 4.8.09032

ORM Solutions Natural ORM Architect   1.0.3049.4-g17343d19 (2023-03)

Steps:

  1. Open the new file dialog image
  2. Select Object-Role Modelling File and click on open image
  3. The dialog disappears, no new file is created.

Expected result: A new .orm file is created in step 3

mcurland commented 8 months ago

I hadn't pushed VS current in a while yet, so I upgraded and will look in the morning. A few random things to look at:

1) Create a new .NET Framework C# (the classic stuff--sorry I haven't updated the heavily customized code generators to the new project system) project and add an item in the project instead of with file new. Believe it or not this a heavily divergent case path (VS SDK driven). 2) Make sure you only picked one of the normal (all users) and per user installs. These are not side-by-side compatible They will happily overwrite each other's keys on install and delete them on uninstall. You'll need to get all versions off to start clean if this happened. 3) Are you able to open an existing .ORM file cleanly?

Let's start there. This is not a problem I've seen before on a clean installation.

-Matt

schelv commented 8 months ago

I'm entirely new to Visual Studio, so I look at point 1 later.

  1. Make sure you only picked one of the normal (all users) and per user installs. These are not side-by-side compatible They will happily overwrite each other's keys on install and delete them on uninstall. You'll need to get all versions off to start clean if this happened.

βœ… extension manager: image

  1. Are you able to open an existing .ORM file cleanly?

Yes I found SampleModel.orm in this repo and it appears to open cleanly. image

  1. Create a new .NET Framework C# project

Is that this one? I previously used this option: image

and add an item in the project instead of with file new.

image

It works! image

Adding it with File > New > File... also works.

In the "Blank Solution", "Object-Role Modeling File" is not listed in the "Add New Item" dialog.

mcurland commented 8 months ago

"Adding it with File > New > File... also works." Isn't this what was originally failing?

As long as your extension snapshot is the marketplace search results and not 'Installed' you're fine. VS lets you designate backup dependencies (a subset constraint in ORM) but not exclusions (an ORM exclusion constraint). In other words, I can't force the system to stop you from installing both.

VS has both Projects (think of a project as a build unit) and Solutions (collections of interdependent projects). To generate code from a .ORM file you currently need a .NET Framework project. .NET Framework is the classic Windows-only .NET, as opposed to the current multi-platform .NET Core (you might see .NET Standard as well). With the newer .NET versions VS also introduced a simplified project file format that is much more reliant on the underlying file system. For NORMA, the problem is that we seriously stretched the VS build system. Basically, we're taking advantage of parts of the old file format to make the VS code generation hook, which is called IVsSingleFileGenerator, produce multiple files. I just haven't tackled the new project systems, which need to fully rearchitect the code generation integration (generator project is around 4500 lines, about half of which won't work).

It looks like your blank solution gave you a project, but it is likely not one that can generate NORMA code. When you add a project, you'll see 3 dropdowns at the top of the dialog (language, target platform, and project type). If you set these to C#/Windows/Console you should see a 'Console App (.NET Framework)'. This is really just a placeholder location to generate your NORMA code. If you do not see this (you will see 'Console App' without the framework tag), then you'll need to add some VS functionality with Tools/Get Tools and Features. Make sure the '.NET desktop development' item is checked in the 'Desktop and Mobile' section.

If you think you're all running properly now feal free to close this out.

For General Community I think this issue should be quite rare, but if you do find that new file isn't working, this is really just a complicated mechanism to open an existing file with a new name and tag. This is the file that is being opened is shown below--you can open it directly (change $fileinputname$ if you like) and then save as. Note that this does not have any GUIDs in the id and ref files, which are usually plentiful in an .ORM file. This causes new GUID identifiers to be generated on load so that all of your .ORM files have different ID sets.

<?xml version="1.0" encoding="utf-8"?>
<?new?>
<ormRoot:ORM2 xmlns:orm="http://schemas.neumont.edu/ORM/2006-04/ORMCore" xmlns:ormDiagram="http://schemas.neumont.edu/ORM/2006-04/ORMDiagram" xmlns:ormRoot="http://schemas.neumont.edu/ORM/2006-04/ORMRoot">
        <orm:ORMModel id="modelId" Name="$fileinputname$"/>
        <ormDiagram:ORMDiagram id="diagramId" IsCompleteView="false" Name="$fileinputname$" BaseFontName="Tahoma" BaseFontSize="0.0972222238779068">
                <ormDiagram:Subject ref="modelId"/>
        </ormDiagram:ORMDiagram>
</ormRoot:ORM2>
schelv commented 8 months ago

"Adding it with File > New > File... also works." Isn't this what was originally failing?

For a blank project:

For a "Windows Forms App (.NET Framework)":

To generate code from a .ORM file you currently need a .NET Framework project.

Ok, that explains things a bit.

It is not very clear to me, but this is how I interpret/understand your explanation (please correct me if I'm wrong): The extension does not directly generate the .orm file? It provides (.NET) code that is used to generate the .orm file? And that is why the .NET framework is needed?

Could the .NET code be compiled before it's made into an extension? That would make more sensen, since making an .orm diagram is a language independent task.

schelv commented 8 months ago

I even understand it less now. Today this is the situation for a new blank project:

File > New > File... , then choosing "Object-Role Modelling File" works fine The button "Add New Item..." under "Project" does not exist.

So I guess it is fixed now?

schelv commented 8 months ago

Either I mixed/messed things up earlier while testing, or Visual Studio is non-deterministic.

I want to better understand the problem so I tested a bit further. I've uninstalled the ".NET desktop development". Made a new blank project. Tried File > New > File... , then choosing "Object-Role Modelling File", nothing happens just like before. When I try to open an existing .orm file I get the following error: image When I again try to open the same existing .orm file I get a different error: image

So I guess the ".NET desktop development" is required, but the type of project does not really matter.

mcurland commented 8 months ago

I'm sorry the early experiences aren't going well.

I don't understand what you mean by a 'blank project'. There is a 'Blank Solution', which is a solution with no projects in it. A solution is just a list of references to projects and dependencies between them. Code files are not placed directly in a solution. That being said, VS has a 'Miscellaneous Files' project that is generally hidden. This is what lets you open files at all when you have a blank solution (this is where you put anything you open with File>New>File). You can see the Misc Files project with Tools/Options/Environment/Documents where you'll see a 'Show Miscellaneous Files in Solution Explorer'. You can also set the number of files to remember (mine is set to 10). With the Solution Explorer window (View/Solution Explorer) open you'll now see the Miscellaneous Files project.

There are also various forms of blank application project templates, but none of these for a .NET Framework, where you have to pick a project type (Console, Windows Forms, etc.).

You obviously should not be getting different results opening the file different times. I generally only see 'Object reference not set...' when trying to generate the files in a non .NET Framework project. To make sure you have the right project type, open the project file (generally .csproj) and look at the root tag. If it says something like <Project Sdk="Microsoft.NET.Sdk"> then you DO NOT have the correct project type. The classic project file will have a xmlns="http://schemas.microsoft.com/developer/msbuild/2003" in the root project tag. [Developer whine: although these are complete different structures and implementations, the GUID identifiers for the projects and project items are exactly the same. If you ask a project item in a C# project for its type it will give you exactly the same value in both systems, which means that you need to behavior test to figure out which system you're in. Unfortunately, the failures appear quite deep in the call stack. It just isn't something I've unwound yet in the code.] Anyway, if you're in the correct project type you should not have any generation errors, one you get that far.

When you say 'open an existing file', how are you getting there? File/Open in .VS? Double-click in File Explorer? The last one can be a little problematic. The association between a file and the app are part of the system registry, which is not available to a Marketplace-style VS package. Earlier NORMA versions (VS2015 and earlier used an .msi setup program, not a .vsix file) directly wrote the .orm file association to the system shell. Now, you need to 'Open With' and choose the VS 2022 or the VS Version Selector as the app to open with. Also, you showed a successfully opened .ORM file earlier. Is that one still working correctly?

This is a lot of somewhat random information, but I'm somewhat at a loss here. Although template registration (file new) has changed somewhat over the years, the basic flow of opening files hasn't been touched since the 2007 timeframe when NORMA was very young. I know .ORM files open in an empty VS environment, and that they work correctly in a .NET Framework project. The project interactions in VS are either very early in the editing process (resolve the new file templates or wizards and associate file contents with an editor type to open a designer) and very late (run code generators and compilers as build steps). Anything in between is in the designer, which doesn't really care what project it is running in. If you're able to get a designer open then I'd suggest working in that environment.

schelv commented 8 months ago

I'm sorry the early experiences aren't going well.

I don't understand what you mean by a 'blank project'. There is a 'Blank Solution', which is a solution with no projects in it.

'Blank Solution' is what I wanted to say.πŸ˜…

Explaining what is happening with words isn't really working so far. Below is a (mostly) visual guide how you can create the "clean installation" that produces the error. Let's hope it is clear this time🀞

Steps to reproduce the error

  1. Make sure Visual Studio Community 2022 is not installed.
  2. Start VisualStudioSetup.exe
  3. image
  4. image
  5. Wait for the installer to finish, and open Visual Studio Community 2022
  6. image
  7. image
  8. Install NORMA from Extensions/Manage Extensions...

New ORM file

  1. File > New > File...
  2. then choosing "Object-Role Modelling File"
  3. nothing happens.

Open existing ORM file

  1. File > Open > File...
  2. Select SampleModel.orm
  3. image
  4. File > Open > File...
  5. Select SampleModel.orm
  6. image
schelv commented 8 months ago

Follow up steps

  1. image
  2. image

New ORM file

  1. File > New > File...
  2. then choosing "Object-Role Modelling File"
  3. πŸ‘

Open existing ORM file

  1. File > Open > File...
  2. Select SampleModel.orm
  3. πŸ‘
mcurland commented 8 months ago

I thought this was strongly recommended in the tutorials, but it looks like it is more of a 'nice-to-have' than a 'required', which understates its importance.

Looking over VS component list it appears that I can add a Microsoft.VisualStudio.Workload.ManagedDesktop dependency for NORMA VSIX files, which should force this on before installing. My current prerequisite is Microsoft.VisualStudio.Component.CoreEditor, which is admittedly boilerplate pulled from other example VSIX files, not researched (basically, I never tracked down what this meant or what else was available).

I don't think I can build or debug NORMA in an empty VS environment as you show, so taking a full day to strip my dev box down to scratch and rebuild multiple times to figure out the tightest set of dependencies isn't high on my list. Also, if I get to the component level I think the VS messages will also be too detailed to be useful. I think the ASP.NET Web Development also enables this, but VSIX manifests doesn't do OR or NOT dependencies, so I'll just pick the desktop one that I know works.

I truly appreciate the legwork trying the different environments. I hope with the correct VS workload in place you'll have a positive experience moving forward with NORMA.

I'll close this out when I get the manifests updated. I'm making some other changes before the next public release (default value support and major enhancements to unary fact types), and I'll close this thread out when that is done.

schelv commented 8 months ago

Sounds good! I've tested a bit and the components below are also required for NORMA:

They are listed as "Recommended" for the Microsoft.VisualStudio.Workload.ManagedDesktop