Water Create Project from command line

Hey
Is there a Command Line argument to create a project in a specific language and for a specific project type. for example:
I want to create a new project:

Project Name: TestProject
Prefered Language: Mercury
Project Type: .Net Standard 2.1

Similar to: .Net New

THX a lot in advance

Harald,

Not currently, no. What’s your end goal for this?

Hey
At the moment, I have a project, which creates .NET Dll’s on the fly.
Means, that I create a .NET Dll depending of some information from another project.
In the MS World, I can use the “dotnet new”, which creates the project as itself and then I can put my code into this file structure and at the endccompile it.

I can also use different targets (like .NET 2.0 or .NET 2.1) depending, where my created .dll is used in the target solution

THX

THX

For now, if you’re willing to write some code, you can reference RemObjects.Elements.ProjectSystem.dll, and use the ElementsProjectFile class in there to create, modify and save project files. It’s what Fire, Water and VS also use to load, save and update projects. The class should be fairly self-explanatory, if you go by Code Completion or look at it in ILSpy.

1 Like

THX - I will give it a try :wink:

1 Like

Don’t hesitate to let me know if you have any questions, or run into any problems.

1 Like

One thing I notice, right now there’s no .cgtor to create a new project w/o file.

I suggest using new ElementsProjectFile withURL(url) Xml(xml), and use this static string to create the xml

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build" ToolsVersion="4.0"/>

I’ll add a new constructor for vNext.

1 Like

Hey Marc.

Something isn’t working for me…
I use the following code:

        Dim locelementsUrl = RemObjects.Elements.RTL.Url.UrlWithFilePath____isDirectory(myBaseProjectFolder, False)
        Dim locFileXml As String = "<?xml version=""1.0"" encoding=""utf-8"" standalone=""yes""?> " &
                                   "<Project xmlns=""http//schemas.microsoft.com/developer/msbuild/2003"" DefaultTargets=""Build"" ToolsVersion=""4.0""/>"
        Dim locRemObjectXMLDocument = RemObjects.Elements.RTL.XmlDocument.FromString(locFileXml)
        Dim locElements As New RemObjects.Elements.CommonProjectSystem.ElementsProjectFile(locelementsUrl, locRemObjectXMLDocument)

And the error is created at the ElementsProjectFile:

at RemObjects.Elements.CommonProjectSystem.ElementsProjectFile.updateElement____withValue__forChildElement(XmlElement element, String value, String name)
at RemObjects.Elements.CommonProjectSystem.ElementsProjectFile.readFromXml()
at RemObjects.Elements.CommonProjectSystem.ElementsProjectFile…ctor(Url url, XmlDocument xml)

Could you please give me some advise…
THX

I’m out of office right now but will have a look when I’m back.

What’s the exception?

Yeah, looks like a few more of the sub-elements in the XML are expected to be there. I’ll fix tomorrow to make this easier; if you can wait for that…

Hey Marc
Thx - I think, I will have to wait :wink:

Hope to hear, how it can be done.

If you don’t wanna wait, Take the xml of an existing project file and just remove all the settings and all the items, but keep the groups.

Use ths version:

RemObjects.Elements.ProjectSystem.dll (63 KB)

Some sample code (Oxygene; but same basics apply to Mercury):

var p := new ElementsProjectFile withURL(Url.UrlWithFilePath("/Users/mh/Desktop/temp.elements")) CreateNew(true);
p.AddConfiguration("Debug");
p.AddConfiguration("Release");
p.setValue("Echoes") forSetting("Mode");
p.setValue(".NETCore5.0") forSetting("TargetFramework");
p.setValue("DEBUG;TRACE") forSetting("ConditionalDefines") configuration("Debug");
p.AddReference(new ElementsProjectObject withKind("Reference") Include("Elements"));
p.AddFile(new ElementsProjectObject withKind("Compile") Include("Program.pas"));

Hey @mh and all others as well

Marc asked me to post my mail to him, because of a better follow up.

So here is question/answer in one thread:

First, your have been right with your latest mail, when I include the complete XML file structure of an existing project (and just let the empty groups), then it seems to work (first of all)

I saw a few things, which let me think about this project…

  1. When I run the Save routine, then in the corresponding path isn’t anything written.

hmm. I’ll check. Pretty sure tis has to be working, coz VS and Water use this too…

Have you tried passing true to the force parameter?

project.Save(true);

–No not yet…

  1. There are a couple of pre-information’s, I would have to define, like the include or the path or even the files.
    This will be a really hard challenge at all…

Let me explain, how it works with the MS tool.
First I have to create the project with the CLI, which is in my case as simple as:
“dotnet new classlib -o “ProjectPath” -f “netstandard2.0” -lang “VB” –force”

Sure, thats just as simple as setting the targetframework (as I showed on talk), with a single one of code. “Language” is irrelevant, as elements detects that from the file extension and c an mix them. So the above is really just two lines of code, now.

What does -force do?

–force

Forces content to be generated even if it would change existing files. This is required when the template chosen would override existing files in the output directory.

With this command, the complete structure is build.
After that, all files, which I create and end with the suffix “.vb” will get recognized on the build, so I don’t have to tell the compiler, which file I would like to include (expecting embedded resource files)

When I look into the XML File “xxx.elements” then I see, that every single class and also file has to be included there. So this will be a massive effort, even because I would have to generate all files first and then create the project (if this would work, because with dotnet it would not work, because everything gets deleted and refreshed)

You can also add “.pas”, say, as a single include. Or “folder*” for recursively all files in that folder.

Hey @mh

I wanted to try your sample code, but it seems, I miss the "Elements.dll, Which should be: “Elements, Version=1.0.0.1, Cultrue=neutral, PublickKeyToken=c8241675aa82e6f8”

THX

Ah, my apologies. These need to match, as i built against a local version of that. I always forget to include that. Will send in 20 mins, waiting for my main Mac to come back up from Software update, right now. My fixes are also now merged and will be in the next official build.

1 Like

Archive.zip (204.0 KB) latest v of both matching dlls

1 Like

THX @mh
The files where created sucessfully. I will go deeper into it within the next couple of days!
THX in advance!

1 Like

any time!