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

$(GitBranch) prop value is empty in .csproj file #178

Closed
sanjaykulkarni04 opened this issue Sep 24, 2021 Discussed in #177 · 2 comments
Closed

$(GitBranch) prop value is empty in .csproj file #178

sanjaykulkarni04 opened this issue Sep 24, 2021 Discussed in #177 · 2 comments

Comments

@sanjaykulkarni04
Copy link

Discussed in #177

Originally posted by sanjaykulkarni04 September 23, 2021
Hello,

While building csproj locally/CI server on master branch, I wanted to add RC NuGet package reference otherwise PRE release NuGet package reference. Please find the below code added in .csproj file. What's wrong with the below code? Can someone assist me?

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <GitBranch>$(GitBranch.Trim())</GitBranch>
  </PropertyGroup>

  <ItemGroup>
	  <PackageReference Include="AutoMapper" Version="10.1.1" />
	  <PackageReference Include="GitInfo" Version="2.2.0" />
    <PackageReference Include="Data.Foundation.Messaging" Version="4.1.5" />    
  </ItemGroup>

	<Choose>
		<When Condition="$(GitBranch) == 'master'">
			<ItemGroup>
				<PackageReference Include="Data.Account.Domain.Messaging" Version="1.0.0-rc*" IncludePrerelease="true" />
			</ItemGroup>
		</When>
		<Otherwise>
			<ItemGroup>
				<PackageReference Include="Data.Account.Domain.Messaging" Version="1.0.0-pre*" IncludePrerelease="true" />
			</ItemGroup>
		</Otherwise>
	</Choose>
  <ItemGroup>
    <ProjectReference Include="..\Data.Account.GraphQl.Schema\Data.Account.GraphQl.Schema.csproj" />
  </ItemGroup>
  
</Project>
```</div>
@sanjaykulkarni04
Copy link
Author

Hello,

I have the latest 2.2.0 version installed. Can someone please help me with this?
In VS .csproj file I can see a warning message - Target GitInfo is not defined.

I wanted to control the NuGet package reference based on $(GitBranch) prop value. If the value is master then refer RC pkg otherwise PRE releases pkg.

I have updated the .csproj file as suggested in #143

<Target Name="PopulateInfo" DependsOnTargets="GitInfo" BeforeTargets="PrepareForBuild">
		<PropertyGroup>
			<PackageId>Crlib</PackageId>
			<Version>$(GitBaseVersion)</Version>
			<Authors>Rcmcpe</Authors>
			<PackageLicenseExpression>MIT</PackageLicenseExpression>
			<RepositoryUrl>$(GitRepositoryUrl)</RepositoryUrl>
			<RepositoryType>git</RepositoryType>
			<RepositoryBranch>$(GitBranch)</RepositoryBranch>
			<RepositoryCommit>$(GitCommit)</RepositoryCommit>
		</PropertyGroup>
	</Target>
	<ItemGroup>
		<PackageReference Include="GitInfo" Version="2.2.0">
			<PrivateAssets>all</PrivateAssets>
			<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
		</PackageReference>    
       </ItemGroup>
       <Choose>
		<When Condition="$(RepositoryBranch) == 'master'">
			<ItemGroup>
				<PackageReference Include="Linedata.Account.Domain.Messaging" Version="1.0.0-rc*" IncludePrerelease="true" />
			</ItemGroup>
		</When>
		<Otherwise>
			<ItemGroup>
				<PackageReference Include="Linedata.Account.Domain.Messaging" Version="1.0.0-pre*" IncludePrerelease="true" />
			</ItemGroup>
		</Otherwise>
	</Choose>

@kzu
Copy link
Member

kzu commented Feb 6, 2023

Target won't be defined until after a successful restore. You can condition that target to $(GitInfoImported) == 'true' to ensure GitInfo has been properly installed and imported.

Also, note that the properties that GitInfo populates are called Git*. So, your RepositoryBranch isn't actually one of the populated props. It should be GitBranch. See https://github.com/devlooped/GitInfo#details

@kzu kzu closed this as completed Feb 6, 2023
@devlooped devlooped locked and limited conversation to collaborators Sep 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants