Drizin / CodegenCS

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

VS2022 17.10.1 HRESULT Error #29

Closed uholeschak closed 2 weeks ago

uholeschak commented 3 weeks ago

When executing a template in VS2022 17.10.1 I get a HRESULT error when the solution is updated:

Loading 'User1.dll'...
Template entry-point: 'UserTemplate.Main()'...
Generated 1 file: 'D:\Projects\EdiabasLib\Tools\Psdz\AssemblyPatcher\Users1.config'
Successfully executed template 'User1.dll'.
CodegenCS - run template successfully finished. Updating Solution Explorer tree...
CodegenCS - error running template: Falscher Parameter. (Ausnahme von HRESULT: 0x80070057 (E_INVALIDARG))

This problem seems to occur only for .NET Framework projects. With NET8 there is no error.

uholeschak commented 3 weeks ago

Another problem is, that when using logger.WriteLineAsync VS2022 hangs and restarts afterwards.

uholeschak commented 3 weeks ago

Another problem is that after a compilation error in the script file it's not possible to compile a second time. Simply nothing happens when calling the custom tool or you get an error message: grafik You have to restart VS to try the next compilation.

Drizin commented 2 weeks ago

When executing a template in VS2022 17.10.1 I get a HRESULT error when the solution is updated: This problem seems to occur only for .NET Framework projects. With NET8 there is no error.

Reproduced and fixed. Please try with version 3.7.1

Drizin commented 2 weeks ago

Another problem is that after a compilation error in the script file it's not possible to compile a second time. Simply nothing happens when calling the custom tool or you get an error message

Also reproduced and fixed. Please try with version 3.7.1

Drizin commented 2 weeks ago

Another problem is, that when using logger.WriteLineAsync VS2022 hangs and restarts afterwards.

I couldn't reproduce this problem.

Does the following code (which works for me) crashes for you?

class MyTemplate
{
    async Task<FormattableString> Main(ILogger logger) 
    {
        await logger.WriteLineAsync($"Generating MyTemplate...");
        return $"My first template";
    }
}

I'm using Microsoft Visual Studio Professional 2022 (64-bit) Version 17.10.2. Can you please update yours to 17.10.2+ and try again?

If the problem persists, can you open CodegenCS.sln, set VS2022Extension as the starting project, launch it, open any existing csproj, run a template to reproduce the problem, and find where exactly the code is crashing?

uholeschak commented 2 weeks ago

Thanks, it seems to work now without any problems! My current VS version is: 17.10.3 In the generated log file the date is not replaced:

Generated by CodegenCS Custom Tool at {DateTime.Now.ToString()}.
For more info please check out https://github.com/Drizin/CodegenCS

Is this a bug?