C
C#ā€¢16mo ago
MrScautHD

ā” MSBuild is it possible to set a additonal property?

Hello i tried already: Main Project:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>

<!-- Define a default value for EnableMyFeature, can be overridden by referencing project -->
<EnableMyFeature>false</EnableMyFeature>
</PropertyGroup>

<PropertyGroup Condition="'$(EnableMyFeature)' == 'true'">
<DefineConstants>$(DefineConstants);MY_CONSTANT</DefineConstants>
</PropertyGroup>

<!-- ... -->
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>

<!-- Define a default value for EnableMyFeature, can be overridden by referencing project -->
<EnableMyFeature>false</EnableMyFeature>
</PropertyGroup>

<PropertyGroup Condition="'$(EnableMyFeature)' == 'true'">
<DefineConstants>$(DefineConstants);MY_CONSTANT</DefineConstants>
</PropertyGroup>

<!-- ... -->
</Project>
Project that referencing this ^^
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>

<!-- Override EnableMyFeature here -->
<EnableMyFeature>true</EnableMyFeature>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="path/to/LibraryProject.csproj">
<AdditionalProperties>EnableMyFeature=$(EnableMyFeature)</AdditionalProperties>
</ProjectReference>
</ItemGroup>

<!-- ... -->
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>

<!-- Override EnableMyFeature here -->
<EnableMyFeature>true</EnableMyFeature>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="path/to/LibraryProject.csproj">
<AdditionalProperties>EnableMyFeature=$(EnableMyFeature)</AdditionalProperties>
</ProjectReference>
</ItemGroup>

<!-- ... -->
</Project>
But idk why i does not work Do i use the right nuget packet?
<PackageReference Include="Microsoft.Build" Version="17.7.2" />
<PackageReference Include="Microsoft.Build" Version="17.7.2" />
2 Replies
MrScautHD
MrScautHDOPā€¢16mo ago
no? wich one need i to use? oh how can i get that one for doing the build thing? šŸ‘ oh so i do not place it there?
<PropertyGroup Condition="'$(EnableMyFeature)' == 'true'">
<DefineConstants>$(DefineConstants);Headless</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(EnableMyFeature)' == 'true'">
<DefineConstants>$(DefineConstants);Headless</DefineConstants>
</PropertyGroup>
Well that is what i use right now should fine right? so i just need to get the right nuget packet ? do i not need MSBuild for it? oh But why does it not work then?
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>true</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AssemblyName>Sparkle</AssemblyName>
<RootNamespace>Sparkle</RootNamespace>
<AssemblyVersion>1.0.3</AssemblyVersion>
<Title>Sparkle</Title>
<Authors>MrScautHD</Authors>
<Description>A fast, Cross-platform .NET 7 C# 11 game engine.</Description>
<PackageProjectUrl>https://stellution.com/</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/MrScautHD/Sparkle/blob/main/LICENSE</PackageLicenseUrl>
<PackageIcon>content\icon.png</PackageIcon>
<RepositoryUrl>https://github.com/MrScautHD/Sparkle</RepositoryUrl>
<PackageTags>OpenGL, Angle, Game, Engine, Renderer, Graphics, C#11, Net7, dotnet, Modern, Sparkle, 2D, 3D, Raylib, Fast, Physics, XNA, Cross-platform, Audio</PackageTags>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Version>2.0.0.0</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(EnableMyFeature)' == 'true'">
<DefineConstants>$(DefineConstants);Headless</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BepuPhysics" Version="2.5.0-beta.13" />
<PackageReference Include="Microsoft.Build" Version="17.7.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Raylib-cs" Version="4.5.0.4" />
</ItemGroup>

<ItemGroup>
<Content Include="content/icon.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>true</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AssemblyName>Sparkle</AssemblyName>
<RootNamespace>Sparkle</RootNamespace>
<AssemblyVersion>1.0.3</AssemblyVersion>
<Title>Sparkle</Title>
<Authors>MrScautHD</Authors>
<Description>A fast, Cross-platform .NET 7 C# 11 game engine.</Description>
<PackageProjectUrl>https://stellution.com/</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/MrScautHD/Sparkle/blob/main/LICENSE</PackageLicenseUrl>
<PackageIcon>content\icon.png</PackageIcon>
<RepositoryUrl>https://github.com/MrScautHD/Sparkle</RepositoryUrl>
<PackageTags>OpenGL, Angle, Game, Engine, Renderer, Graphics, C#11, Net7, dotnet, Modern, Sparkle, 2D, 3D, Raylib, Fast, Physics, XNA, Cross-platform, Audio</PackageTags>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Version>2.0.0.0</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(EnableMyFeature)' == 'true'">
<DefineConstants>$(DefineConstants);Headless</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BepuPhysics" Version="2.5.0-beta.13" />
<PackageReference Include="Microsoft.Build" Version="17.7.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Raylib-cs" Version="4.5.0.4" />
</ItemGroup>

<ItemGroup>
<Content Include="content/icon.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
That is my full .csproj
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnableMyFeature>true</EnableMyFeature>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\src\Sparkle\Sparkle.csproj" >
<AdditionalProperties>EnableMyFeature=$(EnableMyFeature)</AdditionalProperties>
</ProjectReference>
</ItemGroup>

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

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

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnableMyFeature>true</EnableMyFeature>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\src\Sparkle\Sparkle.csproj" >
<AdditionalProperties>EnableMyFeature=$(EnableMyFeature)</AdditionalProperties>
</ProjectReference>
</ItemGroup>

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

</Project>
And with this project i try to override the value i made a method in Sparkle ( Main project ):
#if Headless
public int GetFps() {
return Raylib.GetFPS();
}
#endif
#if Headless
public int GetFps() {
return Raylib.GetFPS();
}
#endif
and when i set it in the Test project to true <EnableMyFeature>true</EnableMyFeature> i can still not call this method thx šŸ‘ is there no other way? Because then i set it with a command cuold i not override it with a project variable because i saw allot of users that did it like that so get this fixed in future? so, is there already a issue made on github? oh ok well i did it now like that:
<PropertyGroup Condition="'$(Configuration)' == 'Debug Headless'">
<DefineConstants>$(DefineConstants);Headless;DEBUG</DefineConstants>
<Optimize>false</Optimize>
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release Headless'">
<DefineConstants>$(DefineConstants);Headless</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug Headless'">
<DefineConstants>$(DefineConstants);Headless;DEBUG</DefineConstants>
<Optimize>false</Optimize>
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release Headless'">
<DefineConstants>$(DefineConstants);Headless</DefineConstants>
</PropertyGroup>
šŸ‘ oh but i can not use the Headless variable
#if !Headless
#if !Headless
in the project that refernce to this ah thx btw just a question is it possible to mark methods as headless with a attribute
<PropertyGroup Condition="('$(Configuration)' != 'Debug_Headless') And ('$(Configuration)' != 'Release_Headless')">
<DefineConstants>$(DefineConstants);HEADED</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="('$(Configuration)' != 'Debug_Headless') And ('$(Configuration)' != 'Release_Headless')">
<DefineConstants>$(DefineConstants);HEADED</DefineConstants>
</PropertyGroup>
[Conditional("HEADLESS")]
[Conditional("HEADLESS")]
i know something like that exists but that is just working on methods and not for classes Or would it possible to do my own and remove all classes and methods from the the compiler? oh ok because if i write everywhere #if.... it could go messy and a atttribute look very fine for that but both would amazing or is there a attribute that can check if a variable true? a normal bool
Accord
Accordā€¢16mo 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.
Want results from more Discord servers?
Add your server