C
C#2y ago
MrScautHD

❔ ✅ Why does this not work???

Stellution.Common add Easel.Headless but i want to remove it, now i tried ProjectRefernce Remove... and it is still in need i to reload something or has anyone a idea?
79 Replies
MrScautHD
MrScautHDOP2y ago
Full Code:
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>false</ImplicitUsings>
<Nullable>disable</Nullable>
<AssemblyName>Stellution.Client</AssemblyName>
<RootNamespace>Stellution.Client</RootNamespace>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Easel\Easel\Easel.csproj" />
<ProjectReference Include="..\Stellution.Common\Stellution.Common.csproj" />
<ProjectReference Remove="..\Easel\Easel\Easel.Headless.csproj" />
</ItemGroup>

<ItemGroup>
<Content Include="content/**/*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<Folder Include="csharp\util" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>false</ImplicitUsings>
<Nullable>disable</Nullable>
<AssemblyName>Stellution.Client</AssemblyName>
<RootNamespace>Stellution.Client</RootNamespace>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Easel\Easel\Easel.csproj" />
<ProjectReference Include="..\Stellution.Common\Stellution.Common.csproj" />
<ProjectReference Remove="..\Easel\Easel\Easel.Headless.csproj" />
</ItemGroup>

<ItemGroup>
<Content Include="content/**/*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<Folder Include="csharp\util" />
</ItemGroup>
</Project>
MrScautHD
MrScautHDOP2y ago
MrScautHD
MrScautHDOP2y ago
its like a duplicate thats why i need to remove it but it does not work yes Client does reference Common But Client has the Grpahic Version of Easel so not the Server Version yk and now is it like a duplicate i need to remove headless but just for the client but idk why it not work any idea? ouf can i add a condition that handle that like just on Common and Server but not on Client? so i can not do that? i mean it is the same project just different csproj files mhh would it possible to change between them? like if Client Easel else Easel.Headless it is basiclly the same project just without graphic things...
Klarth
Klarth2y ago
No. A dependency means, "I need this in order to work" not "I need this in order to work..unless". You're going to have to do some redesign work.
MrScautHD
MrScautHDOP2y ago
:/
Klarth
Klarth2y ago
eg. Create an Easel.Common project with an IEaselGame. Then implement that in both Easel.Headless and Easel (I'd probably rename this to reflect it has rendering). Then create Stellution.Client and Stellution.Server as new projects. You can take the dependency on the correct headless-or-not library. Everything can work with IEaselGame because that part is common.
MrScautHD
MrScautHDOP2y ago
well but Easel is not disigned like this
Klarth
Klarth2y ago
Oh, Easel is not yours?
MrScautHD
MrScautHDOP2y ago
nope
Klarth
Klarth2y ago
https://github.com/piegfx/Easel/tree/master/Easel ree weird for the library author to create the Headless library by putting the csproj into the same library and using preprocessor directives everywhere. I would still recommend similar. Skip the Easel stuff since you can't control that. Actually, hmm 🤔 If you can keep EaselGame itself isolated to a top-level game object, there might be a good option. But it probably ends up leaking everywhere.
MrScautHD
MrScautHDOP2y ago
yea how would you do it? like it is the same project but set a constant if a server the rest the removed but by the client everything is there but it is still the same project and problems like this can not haüüem
Klarth
Klarth2y ago
I would use a different library. That's a significant design defect, IMO, that the library author needs to address. If you can limit where EaselGame is used, you might be able to keep most of the code in Stellution.Common and create small Stellution.Client and Stellution.Server projects that simply handle referencing the right library and then handing off the rest. But EaselGame probably gets used too much for that to be viable. There are probably some build options that are better considering how jank this is. You should be able to conditionally include Easel or Easel.Headless in the csproj depending on some build switch. After that, you might be able to global alias EaselGame as either Easel.EaselGame or Easel.Headless.EaselGame in GlobalUsings. But I'm looking into that. The types don't change so this doesn't matter, which makes it easier. You only need to do separate builds and the conditional package reference...
Aqua
Aqua2y ago
library author here i'm aware this is not the best solution but I don't have the time or incentive to use a Common project at this point of time as it would require a fair amount of rewrite work (sure I could add a ton of branching but I don't want to do that), the headless is not my focus as I do not personally use it myself
Klarth
Klarth2y ago
At this point, after learning that the types overlap, I would do this in the csproj assuming you're only doing one project for the client and server. In this approach, you'll do two builds. You can create build configurations for "Client Release" and "Server Release". At that point, you should be able to use Conditional in the csproj like https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-conditional-constructs?view=vs-2022 There might be a better approach if you split the projects into client/server and put more effort into the build system (template / source generation) to eliminate the redundancies, but this is about the best I can do given the circumstances.
MrScautHD
MrScautHDOP2y ago
well but that would also not make it include able or remove able so just 1 project is on the client or does it?
Klarth
Klarth2y ago
You only want to include one of the libraries per build, not both.
MrScautHD
MrScautHDOP2y ago
yea
MrScautHD
MrScautHDOP2y ago
MrScautHD
MrScautHDOP2y ago
to fix this ^^
Klarth
Klarth2y ago
If you need the same executable to run both rendered and headless, then this won't work.
MrScautHD
MrScautHDOP2y ago
no i just want 1 can you give me a example
Klarth
Klarth2y ago
Right, so you do the conditional package reference based on the build condition. Then you'll only include one.
MrScautHD
MrScautHDOP2y ago
i do not really understand is that not the same that i tried before can you give me a small example what is different?
Klarth
Klarth2y ago
It's not what you were doing at all.
MrScautHD
MrScautHDOP2y ago
but the condition part is the same
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Server>true</Server>
</PropertyGroup>

<ItemGroup Condition="'$(Server)' == 'true'">
<ProjectReference Include="..\Easel\Easel\Easel.Headless.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="RiptideNetworking.Riptide" Version="2.0.0" />
</ItemGroup>

<ItemGroup>
<Folder Include="csharp\events" />
<Folder Include="csharp\registry\types" />
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Server>true</Server>
</PropertyGroup>

<ItemGroup Condition="'$(Server)' == 'true'">
<ProjectReference Include="..\Easel\Easel\Easel.Headless.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="RiptideNetworking.Riptide" Version="2.0.0" />
</ItemGroup>

<ItemGroup>
<Folder Include="csharp\events" />
<Folder Include="csharp\registry\types" />
</ItemGroup>

</Project>
^^ sry i not posted that in before that would not work too
Klarth
Klarth2y ago
Ah, yeah that wasn't in here. That's not complete enough though.
<ItemGroup Condition = "'$(Configuration)' == 'Release Server'">
<ProjectReference Include="..\Easel\Easel\Easel.Headless.csproj" />
</ItemGroup>
<ItemGroup Condition = "'$(Configuration)' == 'Release Client'">
<ProjectReference Include="..\Easel\Easel\Easel.csproj" />
</ItemGroup>
<ItemGroup Condition = "'$(Configuration)' == 'Release Server'">
<ProjectReference Include="..\Easel\Easel\Easel.Headless.csproj" />
</ItemGroup>
<ItemGroup Condition = "'$(Configuration)' == 'Release Client'">
<ProjectReference Include="..\Easel\Easel\Easel.csproj" />
</ItemGroup>
If you want to do it via build configuration. (You'll need to add the debug builds too)
MrScautHD
MrScautHDOP2y ago
you sure that works let me try
Klarth
Klarth2y ago
You need to add the build configurations with those names, but it should work...because the type names overlap.
MrScautHD
MrScautHDOP2y ago
would that possible with that names to?
Klarth
Klarth2y ago
Not sure. Oh, that's the configuration name I guess? I don't use Rider. If so, then probably.
MrScautHD
MrScautHDOP2y ago
does it need the Configuration name the Debug / Release thing?
MrScautHD
MrScautHDOP2y ago
MrScautHD
MrScautHDOP2y ago
or
Klarth
Klarth2y ago
Not sure with how Rider supplies the configuration string. Worst case is that you build with Nuke or some other build system.
MrScautHD
MrScautHDOP2y ago
nahh this solution is not that well
Klarth
Klarth2y ago
I guess I overlooked that you're going to have to build the common library twice here.
MrScautHD
MrScautHDOP2y ago
?
Klarth
Klarth2y ago
Once for the Headless and once for the other. They're different types (even if the names overlap).
MrScautHD
MrScautHDOP2y ago
mhhh
Klarth
Klarth2y ago
I'm not sure if you can do that via GUI. 🤔
MrScautHD
MrScautHDOP2y ago
i think not but the solution is not that well too
Klarth
Klarth2y ago
I don't know how to solve this without a build system. Maybe you can create two csproj in the same source directory for the common library like Easel does. Create Stellution.Common and Stellution.Common.Headless and then reference those from your client/server projects. You won't need the conditional configurations that way. They can't go upstream without a build system to trigger a rebuild of the conditional library, AFAIK. You'd need somebody better at msbuild than I am if that's possible.
MrScautHD
MrScautHDOP2y ago
and what about appsettings,json?
MrScautHD
MrScautHDOP2y ago
i made for server and client a settings.json
MrScautHD
MrScautHDOP2y ago
with
MrScautHD
MrScautHDOP2y ago
and get it like that
MrScautHD
MrScautHDOP2y ago
would that work
Klarth
Klarth2y ago
It can't work AFAIK, because you can't push that config upstream to the library to force a rebuild. (You could do this with a build system like Nuke, but I wouldn't put this as part of a JSON file. Just use a CLI parameter for your build)
MrScautHD
MrScautHDOP2y ago
what is a CLI Paramter?
Klarth
Klarth2y ago
Command line interface parameter.
MrScautHD
MrScautHDOP2y ago
dotnet build Stellution.Server/Stellution.Server.csproj -p:Server=true
dotnet build Stellution.Server/Stellution.Server.csproj -p:Server=true
you mean like that?
Klarth
Klarth2y ago
Yes, but that is not sufficient because the Common library won't rebuild. Which is why I suggested a build system in the worst-case scenario.
MrScautHD
MrScautHDOP2y ago
build system?
Klarth
Klarth2y ago
As you're basically writing a program and can force a Common library rebuild and push that setting upstream into its build. https://github.com/nuke-build/nuke is what I use for my apps that have a build system.
MrScautHD
MrScautHDOP2y ago
Would Easel need that too or just im?
Klarth
Klarth2y ago
https://github.com/stevemonaco/ImageMagitek/blob/main/ImageMagitek.Build/Build.cs as an example script that builds/tests/packages a couple apps No, just yours should be fine.
MrScautHD
MrScautHDOP2y ago
and that would able to handle that? and there is no c# way? because adding a full lib just because 1 variable is a big thing...
Klarth
Klarth2y ago
Well, it's a separate project. Which really saves time when you're at the release point so you can automatically build/test/package and even deploy if you want to. The big concern I have is if debugging will be more difficult. Hmm... I wonder if there's any MSBuild command you can put into a csproj that could force a conditional rebuild of the library.
MrScautHD
MrScautHDOP2y ago
mhh
Klarth
Klarth2y ago
So you can run dotnet via MSBuild in csproj: https://github.com/MapsterMapper/Mapster/blob/master/src/Sample.CodeGen/Sample.CodeGen.csproj So you would have the conditions in the Common library. Then the Exec Commands to build the library as a pre-process step for each the Client and Server (remember to pass the right flag). Seems complicated, so I would probably just try stacking the two csproj in the same folder for the Common library.
MrScautHD
MrScautHDOP2y ago
.... Btw what about this
<ItemGroup>
<ProjectReference Include="..\Stellution.Common\Stellution.Common.csproj">
<Server>false</Server>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Stellution.Common\Stellution.Common.csproj">
<Server>false</Server>
</ProjectReference>
</ItemGroup>
why does this not work
Klarth
Klarth2y ago
Why would that work?
MrScautHD
MrScautHDOP2y ago
<ItemGroup>
<ProjectReference Include="..\Easel\Easel\Easel.csproj" Condition="$(Server) != true" />
<ProjectReference Include="..\Easel\Easel\Easel.Headless.csproj" Condition="$(Server) == true" />

<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="RiptideNetworking.Riptide" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Easel\Easel\Easel.csproj" Condition="$(Server) != true" />
<ProjectReference Include="..\Easel\Easel\Easel.Headless.csproj" Condition="$(Server) == true" />

<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="RiptideNetworking.Riptide" Version="2.0.0" />
</ItemGroup>
ChatGPT tell me that should work but it dont 😦 and now idk
Klarth
Klarth2y ago
It's a really unusual scenario for a dependent to request a conditional build of a library.
MrScautHD
MrScautHDOP2y ago
and is there any check like is the project name ... then this....
ChucklesTheBeard
ChatGPT was banned from stackoverflow within a week of it being made public, for excellent reasons. It's eloquent, confident, convincing... and often extremely wrong.
Klarth
Klarth2y ago
That's not how it's supposed to work.
MrScautHD
MrScautHDOP2y ago
lol mhhhh
Klarth
Klarth2y ago
You're either doing: 1. a conditional build of two "versions" under the same name or 2. two separate library names (which requires two csproj) that you can reference separately. The first is probably going to have debugging issues as you maintain the project even if it's technically possible.
MrScautHD
MrScautHDOP2y ago
... would .NET 8 add it if i make a feature request ... 😅
Klarth
Klarth2y ago
Doubt it. This is a nightmare.
MrScautHD
MrScautHDOP2y ago
.D yea mhh
Klarth
Klarth2y ago
That's why you see libraries split up with dependencies. eg. Something.Wpf, Something.Uwp, Something.Avalonia, Something.Uno, etc on NuGet.
MrScautHD
MrScautHDOP2y ago
yea very messy
Klarth
Klarth2y ago
It's not messy.
MrScautHD
MrScautHDOP2y ago
are we speak now about the solution 2 or what easel should do better
Klarth
Klarth2y ago
2 is going to be more straightforward here, I think.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity. Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server