Skip to content

Instantly share code, notes, and snippets.

@Blokyk
Last active December 8, 2023 00:35
Show Gist options
  • Save Blokyk/72514a25e2a1fb266004c34f8a443db9 to your computer and use it in GitHub Desktop.
Save Blokyk/72514a25e2a1fb266004c34f8a443db9 to your computer and use it in GitHub Desktop.
Generator reference refresh workaround (requires local nuget field)
<Project Sdk="Microsoft.NET.Sdk">
<!-- ...normal msbuild stuff... -->
<PropertyGroup>
<PackageId>YOUR.GENERATOR.NAME</PackageId>
<Version>0.1</Version> <!-- Actual release version -->
<!-- Ensure dynamic verison is only visible to normal builds
and not the IDE -->
<_IsDesignTimeBuild>false</_IsDesignTimeBuild>
<_IsDesignTimeBuild Condition="'$(DesignTimeBuild)' == 'true'">true</_IsDesignTimeBuild>
<Version
Condition="'$(Configuration)'=='Debug' AND '$(_IsDesignTimeBuild)' != 'true'"
>$([System.DateTime]::UtcNow.ToString("yyyy.MMdd.HHmm.ss"))</Version>
<!-- Makes sure the <Version> property reflects the actual version string of
the package (leading zeroes are removed) -->
<!-- fixme: doesn't work on midnight (00:00) or when seconds = 0 -->
<Version Condition="'$(Configuration)'=='Debug' AND '$(_IsDesignTimeBuild)' != 'true'"
>$(Version.Replace(".0", ".").Replace(".0", ".").Replace(".0", "."))</Version>
</PropertyGroup>
<!-- Add the generated package to your local nuget feed -->
<Target Name="UpdateLocalPackage" AfterTargets="Pack">
<Exec Condition="'$(Configuration)'=='Debug'"
Command="nuget add -Source YOUR_LOCAL_NUGET_FEED_PATH '$(OutputPath)$(PackageId).$(Version).nupkg'"
/>
</Target>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment