'C# code generator referenced assembly is not run
I have a problem using source code generators. The actual code generation works fine - as long as I reference the generator as .csproj.
Repository with code: https://github.com/Sigurdur42/EasyI18n
Setup: The generator shall generate code for localizable messages. There are 2 solutions in the repository:
- EasyI18n/EasyI18N.sln: Contains the generator and unit tests consuming the generator csproj
- EasyI18n.PackageConsumer/EasyI18nPackageConsumer/EasyI18nPackageConsumer.sln: Contains a consumer which references the generator as assembly and one which references the locally build nuget package
No analyzer is used in the EasyI18nPackageConsumer.sln. Not even the one where I just reference the assembly and set the required properties manually:
<ItemGroup>
<Reference Include="EasyI18N.Generator" OutputItemType="Analyzer" ReferenceOutputAssembly="false">
<HintPath>..\..\..\nugetPackages\EasyI18N.Generator.dll</HintPath>
</Reference>
</ItemGroup>
The working test is in the solution EasyI18N in EasyI18N.Tests:
The class SimpleGetMessageTest contains this test:
[TestFixture]
public class SimpleGetMessageTest
{
public void EnsureMessageTest()
{
var easyI18n = new EasyI18NContainer("de");
var localizedMessage = easyI18n.GetTestMessage();
Assert.That(localizedMessage, Is.EqualTo("Testnachricht"));
}
}
The method GetTestMessage is generated via analyser from LocalizeTestData.xml.
The consumer project has this code:
using EasyI18n;
namespace EasyI18nAssemblyConsumer
{
public class LanguageConsumer
{
public LanguageConsumer(IEasyI18N easyI18N)
{
// This project consumes the dll
// The analyzer is not run..
var localizedMessage = easyI18N.GetTestMessage();
}
}
}
Here, the GetTestMessage cannot be found - if I check VS analyser for that project, I do not see the EasyI18n one :(
Any help or hint is apprechiated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
