Veggerby.Units.CodeFixes 0.3.0-prerelease0006

This is a prerelease version of Veggerby.Units.CodeFixes.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Veggerby.Units.CodeFixes --version 0.3.0-prerelease0006
                    
NuGet\Install-Package Veggerby.Units.CodeFixes -Version 0.3.0-prerelease0006
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Veggerby.Units.CodeFixes" Version="0.3.0-prerelease0006">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Veggerby.Units.CodeFixes" Version="0.3.0-prerelease0006" />
                    
Directory.Packages.props
<PackageReference Include="Veggerby.Units.CodeFixes">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Veggerby.Units.CodeFixes --version 0.3.0-prerelease0006
                    
#r "nuget: Veggerby.Units.CodeFixes, 0.3.0-prerelease0006"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Veggerby.Units.CodeFixes@0.3.0-prerelease0006
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Veggerby.Units.CodeFixes&version=0.3.0-prerelease0006&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Veggerby.Units.CodeFixes&version=0.3.0-prerelease0006&prerelease
                    
Install as a Cake Tool

Veggerby.Units.CodeFixes

Code fix providers for the Veggerby.Units.Analyzers diagnostics.

This package supplies IDE (Roslyn) code actions that complement the analyzer warnings/errors:

Diagnostic Code Fix Action Effect
VUNITS001 "Convert right operand to left unit" Inserts .ConvertTo(left.Unit) on the right-hand side of a + / - operation between differing unit measurements.
VUNITS002 "Specify UnitFormat.Qualified" Adds UnitFormat.Qualified argument to measurement formatting calls lacking explicit format.

When to Install

Install this package if you want automated fixes in Visual Studio / Rider / VS Code C# extension. The analyzers package (Veggerby.Units.Analyzers) is still required to produce diagnostics; this package only contributes fixes.

In most solutions reference both:

<ItemGroup>
  <PackageReference Include="Veggerby.Units" Version="$(VeggerbyUnitsVersion)" />
  <PackageReference Include="Veggerby.Units.Analyzers" Version="$(VeggerbyUnitsAnalyzersVersion)" PrivateAssets="all" />
  <PackageReference Include="Veggerby.Units.CodeFixes" Version="$(VeggerbyUnitsCodeFixesVersion)" PrivateAssets="all" />
</ItemGroup>

PrivateAssets="all" prevents re‑distribution of analyzer/code fix assets to downstream consumers unless explicitly desired.

Usage Examples

VUNITS001

Before:

var len = new DoubleMeasurement(5, Unit.SI.m);
var time = new DoubleMeasurement(3, Unit.SI.s);
var bad = len + time; // diagnostic VUNITS001

Fix applies:

var fixedValue = len + time.ConvertTo(len.Unit);

VUNITS002

Before:

var energy = new DoubleMeasurement(1, Unit.SI.kg * Unit.SI.m * Unit.SI.m / (Unit.SI.s ^ 2));
var s = energy.ToString(); // diagnostic VUNITS002

Fix applies:

var s2 = energy.Format(UnitFormat.Qualified);

Relationship to Analyzer Package

The analyzers assembly is intentionally kept free of Microsoft.CodeAnalysis.Workspaces to satisfy RS1038 guidance. Code fixes depend on Workspaces APIs and therefore live in this separate package. Both share internal diagnostic descriptors via InternalsVisibleTo.

Versioning

Code fixes follow the same version number as analyzers. A new analyzer rule may ship without an immediate fix; in that case a later version adds the fix while maintaining semantic versioning guidelines.

Limitations

  • Only explicit, safe transformations are offered. No speculative dimensional coercions are applied.
  • Fix all in solution is supported (batch fixer) but still validates each occurrence.

License

MIT – see root repository LICENSE.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.3.0-prerelease0007 124 9/21/2025
0.3.0-prerelease0006 122 9/21/2025
0.2.1 129 9/21/2025