haplokuon / netDxf

.net dxf Reader-Writer
MIT License
995 stars 405 forks source link

conditional compilation #if !NET45 should be enhanced #329

Closed LeiYangGH closed 2 years ago

LeiYangGH commented 2 years ago

If install vs2019 on a new Win10, .net 4.5 won't be installed by default(and even cannot be installed). But .net 4.8 can be installed.

netDxf\netDxf\IO\DxfReader.cs

#if !NET45
                Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
#endif

The code won't compile if re-target the project to .net 4.5.2, 4.6.1, 4.8 etc.

haplokuon commented 2 years ago

If you need to target a different framework you will need to manually edit the "netdxf.csproj" file.

LeiYangGH commented 2 years ago

yes. but after editing it, the code won't compile. The best compability is you just need change the csproj, without other code. This is just enhancement, though.

haplokuon commented 2 years ago

The only thing you need to do is to change the target framework for 4.5 'net45' for the framework 4.8 'net48' in both places of the netdxf.csproj. There is no need to rename the constant 'NET45', that is to handle the changes between the net framework 4 family and previous ones; and the net Standard, net Core, and net 5, and I guess later versions like net 6.

LeiYangGH commented 2 years ago

I have tried so i'm afraid not like that. Encoding.RegisterProvider should be compiled under .net core, right? In .net 4.8, for example, it cannot compile.

haplokuon commented 2 years ago

You must define the constant NET45. There are two places in the netdxf.csproj where you must change 'net45' with 'net48' to compile the library for net framework 4.8, and as I wrote in my previous post you must change them BOTH. One to define the target framework and the other to define the NET45 constant.

The line Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); is only applicable to net standard, net core, net 5, and I guess future net versions like net 6. If it doesn't work for you you are doing something wrong or you have something broken somewhere else.

LeiYangGH commented 2 years ago

ok. i missed another NET45 in the csproj. So NET45 here means 'non-standard', not the target framework itself, right? I think the problem is solved. Thanks!