Directory.Build.props submodule build problem

Having problems with building or using the CefGlue .NET/Mono binding? Ask your questions here.

Moderator: fddima

Directory.Build.props submodule build problem

Postby renedescartes2021 » Wed Dec 07, 2022 12:30 pm

Hello,

I'm looking to build a project out-of-source-tree. This project uses cefglue as a submodule, and cefglue is accordingly in a subdirectory. With MSBuild, the best practice for building a project out-of-source-tree appears to be to use a Directory.Build.props file when taking nuances into consideration, overriding $OutputPath and other logic. The problem is that cefglue doesn't respect this user-supplied Directory.Build.props file as cefglue already has one checked into source control, and won't be built out-of-source-tree.

MSBuild (via Microsoft.Common.props logic) searches up the filesystem for Directory.Build.props and includes the first one it finds, if one exists.

Looking at the documentation, Directory.Build.props appears to me to be a user-supplied file, much like the .user file, which should not be checked into source control as it is intended for user-specific customization, even though it will technically work if checked into source control anyway.

I propose refactoring the contents of cefglue's Directory.Build.props and Directory.Build.targets into a differently named .props and .targets file, and including those in each .csproj and .shfbproj. My question is: would this be acceptable for this project for me to submit a patch to do so? Unfamiliar with this project I do not know the technical reasoning Directory.Build.props was used in the first place, and there may be good reason, and I do not know of all other implications like a maintainer would.

If that is not acceptable, then would a patch be accepted to cefglue's Directory.Build.props to replicate the logic in Microsoft.Common.props, to again search up the filesystem for another Directory.Build.props and include it if one exists?

If neither are acceptable upstream, I will seek to put the patch in the fork.
renedescartes2021
Newbie
 
Posts: 2
Joined: Wed Dec 07, 2022 11:57 am

Re: Directory.Build.props submodule build problem

Postby renedescartes2021 » Wed Jan 04, 2023 1:05 pm

Well I've tinkered for a while and this patch seems satisfactory.

This patch which refactors Directory.Build.{props|targets} into MSBuild/common.{props|targets} and includes those within each project.

Code: Select all
diff --git a/CefGlue.Client/CefGlue.Client.csproj b/CefGlue.Client/CefGlue.Client.csproj
index 024207c..e4f1f42 100644
--- a/CefGlue.Client/CefGlue.Client.csproj
+++ b/CefGlue.Client/CefGlue.Client.csproj
@@ -1,4 +1,7 @@
 <Project Sdk="Microsoft.NET.Sdk">
+  <Import Project="..\MSBuild\common.targets" />
+  <Import Project="..\MSBuild\common.props" />
+
   <PropertyGroup>
     <TargetFramework>net6.0-windows</TargetFramework>
 
diff --git a/CefGlue.Demo.GtkSharp/CefGlue.Demo.GtkSharp.csproj b/CefGlue.Demo.GtkSharp/CefGlue.Demo.GtkSharp.csproj
index 14e10b6..f103c47 100644
--- a/CefGlue.Demo.GtkSharp/CefGlue.Demo.GtkSharp.csproj
+++ b/CefGlue.Demo.GtkSharp/CefGlue.Demo.GtkSharp.csproj
@@ -1,5 +1,8 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="..\MSBuild\common.targets" />
+  <Import Project="..\MSBuild\common.props" />
+
   <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
     <DebugSymbols>true</DebugSymbols>
     <OutputPath>bin\x86\Debug\</OutputPath>
diff --git a/CefGlue.Demo.WinForms/CefGlue.Demo.WinForms.csproj b/CefGlue.Demo.WinForms/CefGlue.Demo.WinForms.csproj
index 4127dcb..5762f29 100644
--- a/CefGlue.Demo.WinForms/CefGlue.Demo.WinForms.csproj
+++ b/CefGlue.Demo.WinForms/CefGlue.Demo.WinForms.csproj
@@ -1,4 +1,6 @@
 <Project Sdk="Microsoft.NET.Sdk">
+  <Import Project="..\MSBuild\common.targets" />
+  <Import Project="..\MSBuild\common.props" />
 
   <PropertyGroup>
     <TargetFramework>net6.0-windows</TargetFramework>
diff --git a/CefGlue.Demo/CefGlue.Demo.csproj b/CefGlue.Demo/CefGlue.Demo.csproj
index 4d9deaa..0babd8d 100644
--- a/CefGlue.Demo/CefGlue.Demo.csproj
+++ b/CefGlue.Demo/CefGlue.Demo.csproj
@@ -1,4 +1,6 @@
 <Project Sdk="Microsoft.NET.Sdk">
+  <Import Project="..\MSBuild\common.targets" />
+  <Import Project="..\MSBuild\common.props" />
 
   <PropertyGroup>
     <TargetFramework>net6.0</TargetFramework>
diff --git a/CefGlue.Samples.WpfOsr/CefGlue.Samples.WpfOsr.csproj b/CefGlue.Samples.WpfOsr/CefGlue.Samples.WpfOsr.csproj
index a0ca97a..68e0d58 100644
--- a/CefGlue.Samples.WpfOsr/CefGlue.Samples.WpfOsr.csproj
+++ b/CefGlue.Samples.WpfOsr/CefGlue.Samples.WpfOsr.csproj
@@ -1,4 +1,6 @@
 <Project Sdk="Microsoft.NET.Sdk">
+  <Import Project="..\MSBuild\common.targets" />
+  <Import Project="..\MSBuild\common.props" />
 
   <PropertyGroup>
     <TargetFramework>net6.0-windows</TargetFramework>
diff --git a/CefGlue.WPF/CefGlue.WPF.csproj b/CefGlue.WPF/CefGlue.WPF.csproj
index 13df94b..be7b9d7 100644
--- a/CefGlue.WPF/CefGlue.WPF.csproj
+++ b/CefGlue.WPF/CefGlue.WPF.csproj
@@ -1,4 +1,6 @@
 <Project Sdk="Microsoft.NET.Sdk">
+  <Import Project="..\MSBuild\common.targets" />
+  <Import Project="..\MSBuild\common.props" />
 
   <PropertyGroup>
     <TargetFramework>net6.0-windows</TargetFramework>
diff --git a/CefGlue.WindowsForms/CefGlue.WindowsForms.csproj b/CefGlue.WindowsForms/CefGlue.WindowsForms.csproj
index f82d879..c90b670 100644
--- a/CefGlue.WindowsForms/CefGlue.WindowsForms.csproj
+++ b/CefGlue.WindowsForms/CefGlue.WindowsForms.csproj
@@ -1,4 +1,6 @@
 <Project Sdk="Microsoft.NET.Sdk">
+  <Import Project="..\MSBuild\common.targets" />
+  <Import Project="..\MSBuild\common.props" />
 
   <PropertyGroup>
     <TargetFramework>net6.0-windows</TargetFramework>
diff --git a/CefGlue/CefGlue.csproj b/CefGlue/CefGlue.csproj
index 15bd551..9b7adaa 100644
--- a/CefGlue/CefGlue.csproj
+++ b/CefGlue/CefGlue.csproj
@@ -1,4 +1,6 @@
 <Project Sdk="Microsoft.NET.Sdk">
+  <Import Project="..\MSBuild\common.targets" />
+  <Import Project="..\MSBuild\common.props" />
 
   <PropertyGroup>
     <TargetFrameworks>net6.0</TargetFrameworks>
diff --git a/Directory.Build.props b/MSBuild/common.props
similarity index 95%
rename from Directory.Build.props
rename to MSBuild/common.props
index 2311a6d..e38ab1e 100644
--- a/Directory.Build.props
+++ b/MSBuild/common.props
@@ -11,7 +11,7 @@
     <DisableTransitiveProjectReferences>true</DisableTransitiveProjectReferences>
 
     <IsPackable>false</IsPackable>
-    <PackageOutputPath>$(MSBuildThisFileDirectory).\artifacts\</PackageOutputPath>
+    <PackageOutputPath>$(MSBuildThisFileDirectory)..\artifacts\</PackageOutputPath>
   </PropertyGroup>
 
   <PropertyGroup>
diff --git a/Directory.Build.targets b/MSBuild/common.targets
similarity index 100%
rename from Directory.Build.targets
rename to MSBuild/common.targets
diff --git a/Xilium.CefGlue.shfbproj b/Xilium.CefGlue.shfbproj
index 5cdcb3d..238bf37 100644
--- a/Xilium.CefGlue.shfbproj
+++ b/Xilium.CefGlue.shfbproj
@@ -1,5 +1,8 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
+  <Import Project="..\MSBuild\common.targets" />
+  <Import Project="..\MSBuild\common.props" />
+
   <PropertyGroup>
     <!-- The configuration and platform will be used to determine which
          assemblies to include from solution and project documentation


I suppose you could rename MSBuild/common.{props|targets} to something else.

There are some github issues on MSBuild relating to the use of Directory.Build.props to redirect build output such as:
dotnet/sdk issue #867

I initially thought it might be the case that Directory.Build.props was used in cefglue to set a variable early on as a solution to some ordering problem, but that doesn't appear to be the case. If that were the case, what is relevant is github dotnet/msbuild issue #1603 which describes a way to not use Directory.Build.props by changing order. Here is the way to change ordering such that Directory.Build.props isn't needed in that case:
Code: Select all
-<Project Sdk="Microsoft.NET.Sdk">
+<Project>
+ <!--Set stuff here before including Microsoft.NET.Sdk when order is important-->
+ <Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>netcoreapp1.1</TargetFramework>
    </PropertyGroup>
+ <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
</Project>


But again, it looks to me like Directory.Build.props was used in cefglue source control for convenience and not as a solution to an ordering problem. But I could be wrong so I thought to write this.
renedescartes2021
Newbie
 
Posts: 2
Joined: Wed Dec 07, 2022 11:57 am


Return to CefGlue Forum

Who is online

Users browsing this forum: Google [Bot] and 22 guests