AdamsLair / duality

a 2D Game Development Framework
https://adamslair.github.io/duality
MIT License
1.4k stars 289 forks source link

Consider switching to .NET SDK style projects #737

Closed Barsonax closed 4 years ago

Barsonax commented 5 years ago

Summary

This is already a requirement for netstandard but we also have netframework projects that we could migrate to .NET sdk style projects. This is not strictly required but might still be preferable.

Analysis

Barsonax commented 5 years ago

You can use netframework as target in a net sdk style project however stuff like WPF, winforms, web applications etc are not supported yet.

Since duality is using winforms this is a bit of a bummer. However what we can do for now is upgrade all projects that do not require winforms.

Maybe when .NET core 3.0 is out winform support in sdk style projects (for netframework) will be there too.

Barsonax commented 5 years ago

Seems there are some more issues. Getting some failing unit tests when I changed DualityTests to be a net sdk style project. Branch can be found here: https://github.com/Barsonax/duality/tree/feature/sdkcsprojs

We should first investigate this further before proceeding. We ran into these issues earlier but now we have a isolated branch with just the sdk style change it might be easier to find out whats going wrong here.

Barsonax commented 5 years ago

Debugging the code both before and after this change resulted in this difference for the RenderRedSquare test: Sdk style project: image

Old style project: image

Might have forgotten something when changing the csproj I think.

Barsonax commented 5 years ago

I think I got it figured out. Net sdk style projects output to a framework specific folder. In this case it would put the test dll in a net472 folder. When running the tests it will run in the context of this net472 folder and will only load plugins that are also in this folder.

The tests have some implicit dependencies on certain duality plugins so they now break.

This behavior can luckily be disabled by setting a property in the csproj. However iam not sure if we want such implicit dependencies though that might be a discussion for a different issue.

Might also be solved if we migrate all projects since they should all end up in a framework specific folder.

EDIT: solved it by adding in <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> to the csproj. This is only needed while we still have a mix of old and new style csprojs.

Barsonax commented 5 years ago

We could also simply add tests that test if we are running the correct backends and not some dummy graphic backend. The tests assume this but its currently not clear.

Barsonax commented 5 years ago

Easy way to add the required entries for resx files in a net sdk csproj:

  1. Add this to your csproj:
    <Compile Update="**\*.Designer.cs">
    <AutoGen>True</AutoGen>
    <DesignTime>True</DesignTime>
    <DependentUpon>$([System.String]::Copy('%(FileName)').Replace('.Designer', '.resx'))</DependentUpon>
    </Compile>
    <EmbeddedResource Update="**\*.resx">
    <Generator>PublicResXFileCodeGenerator</Generator>
    <LastGenOutput>$([System.String]::Copy('%(FileName)')).Designer.cs</LastGenOutput>
    </EmbeddedResource>
  2. Click save in visual studio. The required entries will be added.
  3. You can now remove the entries we added in step 1.