stakx / TypeNameFormatter

A small .NET library for formatting type names à la C#.
MIT License
33 stars 4 forks source link

`TypeName` and `TypeNameFormatOptions` types collide when NuGet package installed in several projects #9

Closed stakx closed 6 years ago

stakx commented 6 years ago
  1. Create a new solution with two projects, say ClassLibrary and ConsoleApp.
  2. Add a reference to ClassLibrary in ConsoleApp.
  3. Install TypeNameFormatter in both projects.
  4. Try to use one of the extension methods in ConsoleApp and observe an error message such as:

CS0121: The call is ambiguous between the following methods or properties: 'TypeNameFormatter.TypeName.GetFormattedName(System.Type, TypeNameFormatter.TypeNameFormatOptions)' and 'TypeNameFormatter.TypeName.GetFormattedName(System.Type, TypeNameFormatter.TypeNameFormatOptions)'

stakx commented 6 years ago

Fixed in dc4cb2add96d01c91041fc90f82d73ae2e91b4b1. This was caused by the types in the TypeNameFormatter namespace being declared public, which isn't the right thing to do for a source code-only distribution.

Now there is a <TypeNameFormatterInternal> MSBuild property which controls whether the library's types will be declared internal or public. For the source code-only NuGet package, this property defaults to "True" (= internal types), but it can be set explicitly in downstream projects.