Assembly Name Auto Update for Source Generators
NEW:
- Generators with ProjectReference are supported now.
- ARM64 support (please give feedback, i cannot easily test this.)
Summary
This extension automatically modifies the AssemblyName of a given assembly (.csproj) and reloads a set of dependent projects in a solution.
This is very useful for developing source generators, as VS/roslyn cannot unload assemblies, forcing you to constantly restart VS. Not Anymore :-)
Support
I created a github repo here where issues can be created:
support repo
Also, there's a demo repo that shows how the extension works here:
demo repo
Usage:
Add a file named AutoUpdateAssemblyName.txt into the root folder of the solution (Solution Items in the Solution Explorer). This file contains the project names of the consuming projects you want to unload + reload when the Source Generator project is rebuilt in Debug, one per line. It now also allows for either paths to the .csproj file (which will be resolved from the solution directory, apparently) and nested solution-specific relative paths (if you don't have a .csproj extension).
Note: comments (lines beginning with ', rem, #, -- or //) as well as whitespace-only lines are ignored.
Next, in the .csproj of the Source Generator project, add a comment <!--AutoUpdateAssemblyName-->
somewhere. This enables the project to be updated by the extension. Then do one of these things:
- In the .csproj, in the
<AssemblyName>
property, make sure to add a .
followed by a number at the end of the Assembly Name, so the extension knows what to increment. If that's not found or failed, the following will be attempted.
- In the .csproj, in the
<AssemblyVersion>
property, make sure to add a .
followed by a number at the end of the Assembly Version, so the extension knows what to increment. If that's not found or failed, the following will be attempted.
- In a
Directory.Build.props
file in the same folder as the solution, add an <AutoIncrementedAssemblyRevision>
property containing an integer value, which will be incremented. YOU need to make sure this property is used in your <AssemblyVersion>
or <AssemblyName>
. If that's not found or failed, nothing will be done. See Samples below:
Note:
currently, the .csproj
parsing is quite crude - i just pick the first part between e.g. <AssemblyName>
and </AssemblyName>
, split that on .
, and try to increment the last split part there. If you require more specific logic, please reach out.
Samples:
Here's an example for a Directory.Build.props file:
<Project>
<PropertyGroup>
<AutoIncrementedAssemblyRevision>9</AutoIncrementedAssemblyRevision>
</PropertyGroup>
</Project>
And this is how you use the property in the <AssemblyVersion>
:
<PropertyGroup>
<AssemblyName>MyGenerator.$(AutoIncrementedAssemblyRevision)</AssemblyName>
</PropertyGroup>
You might want to assign a key combination to the Build.RebuildSelection action (Build > Rebuild <selection>). You can do this in Tools > Options > Environment > Keyboard.
TODO
- Only look at
AutoUpdateAssemblyName.txt
when it's changed, not on each build (it's a small file, so that shouldn't matter, but ... well ...
- get the info from
AutoUpdateAssemblyName.txt
int the generator's .csproj file, optionally.
Changelog
- 1.9.2 - fixed a bug with build events being messed up. Thanks to @PaulBraetz
- 1.8 - Added functionality to work with generators that have ProjectReferences. these are built first and thus i prematurely canceled the operation. Not anymore :-)
- 1.7.2 - Fixed (hopefully) a NRE
- 1.7 - Added functionality to update the AssemblyVersion instead of the AssemblyName or use the property AutoIncrementedAssemblyRevision defined in a Directory.Build.props file in the .sln folder.
- 1.6 - (hopefully) fixed VS crash because of an Error with DTE.ActiveDocument - using VS.Documents.GetActiveDocumentViewAsync now...
- 1.5 - Added arm64 compatibility (please give feedback)
- 1.4.2 - enabled finding nested projects for restarting, improved (hopefully, please give feedback) reloading