CircularReflection 1.0.2
See the version list below for details.
dotnet add package CircularReflection --version 1.0.2
NuGet\Install-Package CircularReflection -Version 1.0.2
<PackageReference Include="CircularReflection" Version="1.0.2" />
paket add CircularReflection --version 1.0.2
#r "nuget: CircularReflection, 1.0.2"
// Install CircularReflection as a Cake Addin #addin nuget:?package=CircularReflection&version=1.0.2 // Install CircularReflection as a Cake Tool #tool nuget:?package=CircularReflection&version=1.0.2
CircularReflection
MSBuild task that re-writes classes as abstract definitions, to allow circular references
This is useful for:
- Auto-generation of references (such as URLs from ASPNet)
- Making
nameof(...)
references - Making
<see cref="..."/>
references in doc comments
Applying the build task to your project
- Reference the NuGet package in the project that wants to read the types
- Add
<InputBase>$(MSBuildProjectDirectory)\..\SourceProject\CsFileDirectory</InputBase>
into a<PropertyGroup>
of any project referencing this package - Rebuild, and start referencing types
<PropertyGroup>
<ReflectionInputBase>$(MSBuildProjectDirectory)\..\SourceProject\CsFileDirectory</ReflectionInputBase>
</PropertyGroup>
Referencing types in your project
The types in the source files will be added with the namespace prefix Reflection
.
So if the source has a class Me.MyPackage.MyClass
, the generated type will be Reflection.Me.MyPackage.MyClass
Adding more using directives
If you are referencing files between different targets, you may need to include extra namespaces into the output.
<PropertyGroup>
<ReflectionAdditionalUsings>System;System.Collections.Generic;System.Threading.Tasks;</ReflectionAdditionalUsings>
</PropertyGroup>
Removing namespace
Stubs
By default, each using ...;
namespace will have a stub class defined for it. This means the generated
code should compile without requiring additional code to get generated code to build, but can result in the
compiled assembly containing leaked namespaces.
If you set ReflectionNamespaceStubs
to false
, no stub are added, so namespaces are not leaked into generated assemblies. You may need to
add some 'fake' namespaced classes to have a reliable build.
<PropertyGroup>
<ReflectionNamespaceStubs>false</ReflectionNamespaceStubs>
</PropertyGroup>
Generated files
The generated files are written to the project's obj
directory
in a file named CircularReflection.generated.cs
.
This will be linked into the sources as part of the build.
If required, the output can be moved with the ReflectionOutputBase
setting
Development of the package
Building the NuGet package
First, always do a clean and rebuild.
Update the versions to match in the project properties ( assembly and nuget), and the nuspec file.
Open a terminal in the directory of CircularReflection.csproj
,
and run the command dotnet pack -o ..
.
References
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.