Drizin / CodegenCS

C# Toolkit for Code Generation (T4 alternative!)
MIT License
223 stars 30 forks source link

Command line tools only support Net 5.0 #15

Closed silenuz closed 1 year ago

silenuz commented 1 year ago

I tried to use the command line tools to get a model from a database schema however it wouldn't run as I only have Net 6 and 7 currently installed, and the command line tools require Net 5 which reached EOL in May of last year.

You must install or update .NET to run this application.

App: /home/jordan/.dotnet/tools/dotnet-codegencs Architecture: x64 Framework: 'Microsoft.NETCore.App', version '5.0.0' (x64) .NET location: /usr/share/dotnet

The following frameworks were found: 6.0.14 at [/usr/share/dotnet/shared/Microsoft.NETCore.App] 6.0.15 at [/usr/share/dotnet/shared/Microsoft.NETCore.App] 7.0.3 at [/usr/share/dotnet/shared/Microsoft.NETCore.App] 7.0.4 at [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Learn about framework resolution: https://aka.ms/dotnet/app-launch-failed

To install missing framework, download: https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=5.0.0&arch=x64&rid=opensuse-leap.15.4-x64

Drizin commented 1 year ago

@silenuz I've just upgraded to net6.0 / net7.0, and I've republished dotnet-codegencs (v3.1.4). Can you please check if it works fine?

JasonNewellAtAllegro commented 1 year ago

Nope image

JasonNewellAtAllegro commented 1 year ago

image

I need to use .NET6 (LTS) untile .NET 8 is released and Raw String Literals need .NET 7 which is another issue.

Drizin commented 1 year ago

Did you try this in csproj? <LangVersion>preview</LangVersion> https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version

Drizin commented 1 year ago

@JasonNewellAtAllegro I'm confused. What exactly are you trying to do? Dotnet tool dotnet-codegencs is what was republished, and now it should work in any computer with .NET6/.NET7. But looks like what you need it just to add the Core Library (CodgenCS.Core) inside your project? Codegen libraries are all compatible with netstandard2.0, so they should work in .NET6/.NET7 (I guess I don't need to republish the nugets to specifically target those frameworks). And about using Raw String Literals you need C#11, so yeah if you're project is using .NET6 you'll have to enable the C#11 lang "preview" - like I've mentioned above.

JasonNewellAtAllegro commented 1 year ago

Sorry, I'm in the UK so your reply was outwith my working hours. The dotnet tool will not install because it says their is a package error so couldn't use it. I then switched to the Visual Studio 2022 extension before hitting the raw string issue. I wanted to generate a package with code autogenerated to the correct namespace as it extends log4net instead of making copies manually. It was just an idea.

Drizin commented 1 year ago

@JasonNewellAtAllegro the dotnet tool is supposed to be installed using dotnet tool install (check this) - it's not supposed to be connected to (or dependent on) Visual Studio. The Visual Studio Extension should be equivalent but unfortunately (like any VS Extension) it has some more dependencies and therefore some incompatibilities.

If you want to reverse-engineer databases and run templates, then dotnet-codegencs is what you need. If you want to run templates from inside Visual Studio, then the extension is what you need. (it doesn't have the reverse engineer yet). You only need to install CodegenCS libraries (or source code) if you're extending it (customizing).

silenuz commented 1 year ago

Sorry was out of town all week.

The new version does seem to work, however dumping a schema to a model does not.

Executing 'ExtractWizard' template... Database Type is MSSQL

Reading Database... Unhandled exception: System.ArgumentException: Format of the initialization string does not conform to specification starting at index 72. at System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue) at System.Data.Common.DbConnectionOptions.ParseInternal(Dictionary2 parsetable, String connectionString, Boolean buildChain, Dictionary2 synonyms, Boolean firstKey) at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Dictionary`2 synonyms) at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) at System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key) at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) at System.Data.SqlClient.SqlConnection..ctor(String connectionString) at CodegenCS.Models.DbSchema.Extractor.ExtractWizard.b__140() in //src/Models/CodegenCS.Models.DbSchema.Extractor/ExtractWizard.cs:line 81 at CodegenCS.Models.DbSchema.Extractor.SqlServer.SqlServerSchemaReader.ExportSchemaToJSON() in //src/Models/CodegenCS.Models.DbSchema.Extractor/MSSQL/SqlServerSchemaReader.cs:line 23 at CodegenCS.Models.DbSchema.Extractor.ExtractWizard.Run() in //src/Models/CodegenCS.Models.DbSchema.Extractor/ExtractWizard.cs:line 83 at CodegenCS.Models.DbSchema.Extractor.CliCommand.HandleCommand(ParseResult parseResult, DbSchemaExtractorArgs cliArgs) in /_/src/Models/CodegenCS.Models.DbSchema.Extractor/CliCommand.cs:line 53 at System.RuntimeMethodHandle.InvokeMethod(Object target, Void* arguments, Signature sig, Boolean isConstructor) at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr args, BindingFlags invokeAttr)

Drizin commented 1 year ago

Can you share your command line? You can replace user and password. It looks like you have a bad connection string.

silenuz commented 1 year ago

dotnet-codegencs model dbschema extract mssql "Server=192.168.0.6; Database=WarhammerStats; User Id=sa; Password=****;****" WarhammerStats-Schema.json

Note there is an actual semi colon in the pass, I assume that perhaps that's the problem?

So I verified it is the semicolon in the password and not a problem with the tool. I tried escaping with a backslash but that didn't work, so I tried double quotes around the password, but that breaks the arguments, finally got it to work with single quotes around the pass like so:

dotnet-codegencs model dbschema extract mssql "Server=192.168.0.6; Database=WarhammerStats; User Id=sa; Password='******;********'" WarhammerStats-Schema.json

Thanks.