Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.2 New csproj style with backport of Godot.NET.Sdk #41408

Merged
merged 3 commits into from
Aug 20, 2020

Conversation

neikeq
Copy link
Contributor

@neikeq neikeq commented Aug 20, 2020

There are a lot of build issues coming from old style projects. At this point fixing every single one of those would require adding patch after patch to the project file, which is a considerable amount work and makes the csproj even more bloated than it already is.

As such I decided this effort would be better spent back-porting the Sdk style support that's already available in 4.0-dev to the 3.2 branch.

This will prevent many issues, but it will also introduce other benefits, among them:

  • While target framework stays as .NET Framework v4.7.2, it can be changed to .NET Standard 2.0 or greater if desired.
  • It makes it much easier to add future patches. They are added to Godot.NET.Sdk and the only change required in Godot code is to update the Sdk version to use.
  • Default Godot define constants are also backported, which fixes IDE issues with the preprocessor.

There are a few differences in the changes applied during patching of the csproj compared to 4.0 with the purpose of preventing breaking builds:

  • TargetFramework stays net472 both for new projects and when importing old ones. It can be manually changed to netstandard 2.0+ if desired though.

The following features are enabled by default for new projects. Enabling them in imported projects may result in errors that must be fixed manually:

  • EnableDefaultCompileItems is disabled as it can result in undesired C# source files being included. Existing include items are kept. As long as EnableDefaultCompileItems remains disabled, Godot will continue taking care of adding and removing C# files to the csproj.
  • GenerateAssemblyInfo is disabled as it guarantees a build error because of conflicts between the existing AssemblyInfo.cs and the auto-generated one.
  • Deterministic is disabled because it doesn't like wildcards in the assembly version (1.0.*) that was in the old AssemblyInfo.cs.

Of importance:

This is a breaking change. A great effort was put in avoiding build errors after upgrading a project, but there may still be exceptions.

This also breaks forward compatibility. Projects opened with Godot 3.2.3 won't work out of the box with older Godot versions. This was already the case with changes introduced in 3.2.2.

Albeit C# support in 3.2.x was still labeled as alpha, we've been trying to treat it as stable for some time. Still the amount of problems this change solves justifies it, but no more changes that break project compatibility are to be introduced from now on (at least for 3.x).

Fixes #30970
Fixes #41241


The 'Microsoft.Build' upgrade is needed in order to support reading and editing project files that use Sdks (which this PR introduces) as well as other new features.
A common example of issues with new features is having to specify a PackageReference version with a child element rather than the attribute. This is no longer the case now.
Fixes #15386

neikeq added 3 commits August 20, 2020 21:38
Not sure if we should check revision too, but this is good enough for what we want.
This will be needed to load the correct Microsoft.Build when we switch to the nuget version.

Manual cherry-pick of af4acb5 (relevant parts)
This upgrade is needed in order to support
reading and editing project files that use Sdks
as well as other new features. A common example
in 3.2 is having to specify a PackageReference
version with a child element rather than the
attribute. This is no longer the case now.

Partial cherry-pick of f3bcd5f
Most of the other changes from that commit were already partially
cherry-picked in 3928fe2.
This is a cherry-pick of
ced77b1
with several 3.2 specific alterations.

There are a lot of build issues coming from
old style projects. At this point fixing every
single one of those would require adding patch
after patch to the project file, which is a
considerable amount work and makes the csproj
even more bloated than it already is.

As such I decided this effort would be better
spent back-porting the Sdk style support that's
already available in 4.0-dev to the 3.2 branch.

This will prevent many issues, but it will also
introduce other benefits, among them:

- While target framework stays as .NET Framework
  v4.7.2, it can be changed to .NET Standard 2.0
  or greater if desired.
- It makes it much easier to add future patches.
  They are added to Godot.NET.Sdk and the only
  change required in Godot code is to update the
  Sdk version to use.
- Default Godot define constants are also
  backported, which fixes IDE issues with the
  preprocessor.

There are a few differences in the changes
applied during patching of the csproj compared
to 4.0 with the purpose of preventing breaking
builds:

- 'TargetFramework' stays net472 both for new
  projects and when importing old ones. It can
  be manually changed to netstandard 2.0+ if
  desired though.

The following features are enabled by default for
new projects. Enabling them in imported projects
may result in errors that must be fixed manually:

- 'EnableDefaultCompileItems' is disabled as it
  can result in undesired C# source files being
  included. Existing include items are kept.
  As long as 'EnableDefaultCompileItems' remains
  disabled, Godot will continue taking care of
  adding and removing C# files to the csproj.
- 'GenerateAssemblyInfo' is disabled as it
  guarantees a build error because of conflicts
  between the existing 'AssemblyInfo.cs' and the
  auto-generated one.
- 'Deterministic' is disabled because it doesn't
  like wildcards in the assembly version (1.0.*)
  that was in the old 'AssemblyInfo.cs'.

Of importance:

This is a breaking change. A great effort was
put in avoiding build errors after upgrading a
project, but there may still be exceptions.

This also breaks forward compatibility. Projects
opened with Godot 3.2.3 won't work out of the box
with older Godot versions. This was already the
case with changes introduced in 3.2.2.

Albeit C# support in 3.2.x was still labeled as
alpha, we've been trying to treat it as stable
for some time. Still the amount of problems this
change solves justifies it, but no more changes
that break project compatibility are to be
introduced from now on (at least for 3.x).
@akien-mga
Copy link
Member

Thanks!

@akien-mga
Copy link
Member

TargetFramework stays net472 both for new projects and when importing old ones. It can be manually changed to netstandard 2.0+ if desired though.

For .NET newbies like me, the corresponding moniker is netstandard2.1 as per https://docs.microsoft.com/en-us/dotnet/standard/frameworks

Tested locally on Windows with a pre-3.2.3 RC 5 build and it seems to work fine on the Dodge the Creeps C# demo. I was able to use C# 8.0 features like readonly struct members.

@ghost
Copy link

ghost commented Sep 27, 2020

The new .csproj seems to enforce the use of the editor to create and move scripts and the ability to disable the "auto update project" option is gone. Is there a way to still be able to do all of this through the IDE without relying on the editor at any point ?

@neikeq
Copy link
Contributor Author

neikeq commented Sep 27, 2020

@8nouk The new Sdk does not impose any of this. The project either includes the scripts automatically if the EnableDefaultCompileItems property is not disabled. Otherwise Godot takes care of adding the scripts to the csproj.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants