Closed r-pankevicius closed 5 months ago
I solved this installing .net core 3.1 runtime.
Update to this issue. We're also starting to see a similar thing but with a different set of warnings:
The output from 'csharp-models-to-json' contains invalid JSON.
warning NETSDK1138: The target framework 'netcoreapp3.1' is out of support and will not receive security updates in the future. Please refer to https://aka.ms/dotnet-core-support for more information about the support policy.
warning NU1903: Package 'Newtonsoft.Json' 12.0.3 has a known high severity vulnerability, https://github.com/advisories/GHSA-5crp-9r3c-p9vr
For new team members, installing .net core 3.1 runtime does not fix this issue. I had to recompile the csharp-models-to-json project using .net 7 after updating the target platform and updating the nuget packages. Then I zipped that up to distribute to the team and am having team members replace the csharp-models-to-json folder in their node modules with the new one.
I can confirm this does fix it.
Obviously, this is less than ideal as any reinstall of the node modules will blow away this change. Thankfully, this conversion process for us is not a part of ci, otherwise we'd probably have to look into forking the library.
I think it would be valuable to have this library updated to .net 7 at least. Alternatively, you may be able to compile multiple versions (though this will admittedly increase the package size).
Just some thoughts for improvement as well as a sure-fire way for anyone else with this problem to solve it. You could easily change the .net version to support whatever environment you are working with.
Update to the above. We've gone ahead and moved the library out of node modules and into our main codebase. This effectively creates a local fork with the update to .net 7.
That's different issue. Can be fixed by changing csharp-models-to-json.csproj:
<TargetFramework>net8.0</TargetFramework>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
@r-pankevicius yes, the underlying issue is different but it produces a similar effect on the json output. I found this thread in my own search for a solution so I figured it was a reasonable place to give my own update. Did moving to 8.0 resolve your original issue as well?
@calebeno It doesn't matter .net 8.0 or 7.0. Should work for both, Newtonsoft.Json must be updated.
That was my solution as well. We moved the package out of node modules and into a lib folder within our project. Unfortunate but seems to be what has to be done.
Worked well, @calebeno :
npm uninstall csharp-models-to-typescript
Put csharp-models-to-typescript sources under folder lib/csharp-models-to-typescript
Made 2 tweaks mentioned in this thread
In package.json changed from
"generate-types": "csharp-models-to-typescript --config=cs-to-ts-config.json"
to
"generate-types": "node ./lib/csharp-models-to-typescript/index.js --config=cs-to-ts-config.json"
Last thing was to change container csproj of .net web app to exclude csharp-models-to-typescript inner csproj-s:
<ItemGroup>
<Compile Remove="ClientApp\lib\**" />
<Content Remove="ClientApp\lib\**" />
<EmbeddedResource Remove="ClientApp\lib\**" />
</ItemGroup>
Version: "csharp-models-to-typescript": "^0.21.1"
After recent Visual Studio 2022 update I started to get NU1803 warnings compiling projects (actually not compiling, but restoring). And
npm run generate-types
stopped working.generate-types
defined in package.json scripts:Output from
npm run generate-types
:Proper JSON goes after warnings.
The quick fix is to change line in index.js to remove warning lines:
to this: