devlooped / GitInfo

Git and SemVer Info from MSBuild, C# and VB

Home Page:https://clarius.org/GitInfo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MSBuild variables don't work for MAUI projects

DoctorKrolic opened this issue · comments

Describe the Bug

MSBuild variables like $(GitRepositoryUrl) etc. don't work for MAUI projects and are replaced with empty blank strings

Steps to Reproduce

  1. Create MAUI app
  2. Initialize git repository
  3. Install GitInfo
  4. Go to .csproj file
  5. Replace <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion> with <ApplicationDisplayVersion>1.$(GitSemVerMinor)</ApplicationDisplayVersion>
  6. Try to build the project

Expected Behavior

Project build is successful and $(GitSemVerMinor) is replaced with a propper minor version number (if we just initialized git repository it should be 0)

Actual behaviour

Project build fails with error NETSDK1018: Invalid NuGet version string: '1.'. - as we see $(GitSemVerMinor) was replaced with a blank line leading to invalid version 1.

Version Info

GitInfo 2.2.0
Visual Studio 17.3.3
.NET 6

Additional Info

Tried on 2 different PCs and got the same results

Update: I've read, that I need to depend on GitInfo target. Ok, I added this line to my .csproj:

<Target Name="PopulateInfo" DependsOnTargets="GitInfo" BeforeTargets="PrepareForBuild" />

Now I am getting: MSB4057: The target 'GitInfo' does not exist in the project. However, if I remove that line, I can access ThisAssembly class from my code, so some kind of work is actually running...

Hi there. You'll find some more information on how MSBuild evaluation works at https://learn.microsoft.com/en-us/visualstudio/msbuild/build-process-overview?view=vs-2022.

I'm quite sure you're attempting to use the GitInfo-populated properties (which come from targets) in your csproj property groups. That will never work, as explained in the linked docs, by design. It's not something GitInfo can "fix" for you.

You should, instead, populate that property from within your new target that depends on GitInfo itself, such as:

<Target Name="PopulateInfo" DependsOnTargets="GitInfo" BeforeTargets="PrepareForBuild">
  <PropertyGroup>
      <ApplicationDisplayVersion>1.$(GitSemVerMinor)</ApplicationDisplayVersion>
  </PropertyGroup>
</Target>

Note how given that this target runs after GitInfo, the property group can properly set the value you're seeking now.