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

Godot.NET.Sdk/3.2.4 - Fix targeting .NETFramework with .NET 5 #44135

Merged
merged 4 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<Authors>Godot Engine contributors</Authors>

<PackageId>Godot.NET.Sdk</PackageId>
<Version>3.2.3</Version>
<PackageVersion>3.2.3</PackageVersion>
<Version>3.2.4</Version>
<PackageVersion>3.2.4</PackageVersion>
<PackageProjectUrl>https://github.com/godotengine/godot/tree/master/modules/mono/editor/Godot.NET.Sdk</PackageProjectUrl>
<PackageType>MSBuildSdk</PackageType>
<PackageTags>MSBuildSdk</PackageTags>
Expand Down
2 changes: 0 additions & 2 deletions modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<PropertyGroup>
<!-- Determines if we should import Microsoft.NET.Sdk, if it wasn't already imported. -->
<GodotSdkImportsMicrosoftNetSdk Condition=" '$(UsingMicrosoftNETSdk)' != 'true' ">true</GodotSdkImportsMicrosoftNetSdk>

<GodotProjectTypeGuid>{8F3E2DF0-C35C-4265-82FC-BEA011F4A7ED}</GodotProjectTypeGuid>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! Why have you removed GodotProjectTypeGuid?
Rider UnitTesting feature uses it for special casing Godot project.
https://github.com/JetBrains/godot-support/blob/f6d1349dfad81fc127a53e7c0671d95c6752770c/resharper/src/UnitTesting/GodotRunHostProvider.cs#L50

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to fix it by adding ProjectTypeGuids manually.
van800/godot-demo-projects@03594a8

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used ProjectTypeGuids for the Visual Studio project system, but it no longer has any effect after we switched to Sdk style csproj. The property prevents Visual Studio for Mac from opening the project unless the Godot extension is installed, which I consider a problem, so it was removed. Could Rider do something different for special casing Godot projects? If not I'm willing to add it back (and maybe it works BuildingByReSharper condition?).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll see, what I can do, thank you for clarification.

</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
<Project>
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" Condition=" '$(GodotSdkImportsMicrosoftNetSdk)' == 'true' " />

<PropertyGroup>
<EnableGodotProjectTypeGuid Condition=" '$(EnableGodotProjectTypeGuid)' == '' ">true</EnableGodotProjectTypeGuid>
<ProjectTypeGuids Condition=" '$(EnableGodotProjectTypeGuid)' == 'true' ">$(GodotProjectTypeGuid);$(DefaultProjectTypeGuid)</ProjectTypeGuids>
</PropertyGroup>

<PropertyGroup>
<!--
Define constant to determine whether the real_t type in Godot is double precision or not.
Expand All @@ -16,7 +11,7 @@
</PropertyGroup>

<!-- Backported from newer Microsoft.NET.Sdk version -->
<Target Name="IncludeTargetingPackReference" BeforeTargets="_GetRestoreSettingsPerFramework;_CheckForInvalidConfigurationAndPlatform"
<Target Name="GodotIncludeTargetingPackReference" BeforeTargets="_GetRestoreSettingsPerFramework;_CheckForInvalidConfigurationAndPlatform"
Condition=" '$(GodotUseNETFrameworkRefAssemblies)' == 'true' and '$(TargetFrameworkMoniker)' != '' and '$(TargetFrameworkIdentifier)' == '.NETFramework' and '$(AutomaticallyUseReferenceAssemblyPackages)' == 'true' ">
<GetReferenceAssemblyPaths
TargetFrameworkMoniker="$(TargetFrameworkMoniker)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<ItemGroup>
<Reference Include="Microsoft.Build" />
<PackageReference Include="Microsoft.Build" Version="16.5.0" />
<PackageReference Include="semver" Version="2.0.6" />
<PackageReference Include="JetBrains.Annotations" Version="2019.1.3.0" ExcludeAssets="runtime" PrivateAssets="all" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ namespace GodotTools.ProjectEditor
{
public static class ProjectGenerator
{
public const string GodotSdkVersionToUse = "3.2.3";

public static string GodotSdkAttrValue => $"Godot.NET.Sdk/{GodotSdkVersionToUse}";
public const string GodotSdkVersionToUse = "3.2.4";
public const string GodotSdkNameToUse = "Godot.NET.Sdk";

public static ProjectRootElement GenGameProject(string name)
{
Expand All @@ -19,7 +18,7 @@ public static ProjectRootElement GenGameProject(string name)

var root = ProjectRootElement.Create(NewProjectFileOptions.None);

root.Sdk = GodotSdkAttrValue;
root.Sdk = $"{GodotSdkNameToUse}/{GodotSdkVersionToUse}";

var mainGroup = root.AddPropertyGroup();
mainGroup.AddProperty("TargetFramework", "net472");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Linq;
using JetBrains.Annotations;
using Microsoft.Build.Construction;
using Microsoft.Build.Globbing;
using Semver;

namespace GodotTools.ProjectEditor
{
Expand Down Expand Up @@ -189,7 +191,7 @@ public static string[] GetIncludeFiles(string projectPath, string itemType)
continue;


string normalizedRemove= item.Remove.NormalizePath();
string normalizedRemove = item.Remove.NormalizePath();

var glob = MSBuildGlob.Parse(normalizedRemove);

Expand Down Expand Up @@ -233,7 +235,7 @@ public static void MigrateToProjectSdksStyle(MSBuildProject project, string proj
if (!string.IsNullOrEmpty(root.Sdk))
return;

root.Sdk = ProjectGenerator.GodotSdkAttrValue;
root.Sdk = $"{ProjectGenerator.GodotSdkNameToUse}/{ProjectGenerator.GodotSdkVersionToUse}";

root.ToolsVersion = null;
root.DefaultTargets = null;
Expand Down Expand Up @@ -408,11 +410,32 @@ void RemoveNamespace(XElement element)

public static void EnsureGodotSdkIsUpToDate(MSBuildProject project)
{
string godotSdkAttrValue = $"{ProjectGenerator.GodotSdkNameToUse}/{ProjectGenerator.GodotSdkVersionToUse}";

var root = project.Root;
string godotSdkAttrValue = ProjectGenerator.GodotSdkAttrValue;
string rootSdk = root.Sdk?.Trim();

if (!string.IsNullOrEmpty(root.Sdk) && root.Sdk.Trim().Equals(godotSdkAttrValue, StringComparison.OrdinalIgnoreCase))
return;
if (!string.IsNullOrEmpty(rootSdk))
{
// Check if the version is already the same.
if (rootSdk.Equals(godotSdkAttrValue, StringComparison.OrdinalIgnoreCase))
return;

// We also allow higher versions as long as the major and minor are the same.
var semVerToUse = SemVersion.Parse(ProjectGenerator.GodotSdkVersionToUse);
var godotSdkAttrLaxValueRegex = new Regex($@"^{ProjectGenerator.GodotSdkNameToUse}/(?<ver>.*)$");

var match = godotSdkAttrLaxValueRegex.Match(rootSdk);

if (match.Success &&
SemVersion.TryParse(match.Groups["ver"].Value, out var semVerDetected) &&
semVerDetected.Major == semVerToUse.Major &&
semVerDetected.Minor == semVerToUse.Minor &&
semVerDetected > semVerToUse)
{
return;
}
}

root.Sdk = godotSdkAttrValue;
project.HasUnsavedChanges = true;
Expand Down