MrAdvice icon indicating copy to clipboard operation
MrAdvice copied to clipboard

Distributing MrAdvice within other NuGet library

Open EvilVir opened this issue 8 months ago • 1 comments

Hi,

I'm struggling with this for a moment and I feel I hit the wall. I'm working on larger project, for which I have set of "Core" library prepared with common stuff like logging, hosting and telemetry. This "Core" library is then distributed via private nugets feed so each microservice we write is equiped with standarized set of helpers to speed up the development. One element of "Core" are our custom Advices. It looks like this more-or-less:

  • CoreLib

    • MrAdvice PackageReference
    • OurCustomAdviceAttribute
  • MicroserviceA

    • CoreLib PackageReference
    • SomeClassA marked with OurCustomAdvice
  • MicroserviceB

    • CoreLib PackageReference
    • SomeClassB marked with OurCustomAdvice

Now my problem is that I need to also reference MrAdvice in both MicroserviceA and MicroserviceB to make it all work. This is doable but I'd like to cut the boilerplate to the minimum. So what I did was adding the CoreLib.targets file to the CoreLib looking like this:

<Project>
	<ItemGroup>
		<PackageReference Include="MrAdvice" Version="2.19.1" />
	</ItemGroup>
</Project>

This automatically adds MrAdvice to any project that refences CoreLib nuget and when I build such project (MicroserviceA or MicroserviceB in this example) it works, weaving is done properly, everybody happy.

Problem is that this does not work when doing dotnet build/publish/pack/msbuild. Other things from my CoreLib.targets (global usings, assembly version/author etc.) are picked up but MrAdvice.target is not.

I tried all possibile combinations of PrivateAssets/ExcludeAssets/IncludeAssets settings and no go. Any idea how I can pull this off?

I also tried to run MrAdvice.Weaver.exe command line tool but didn't had luck making it work neither, it just showed messages that there is nothing to weave. IDK maybe I picked wrong DLL (the one from BIN rather than OBJ) but didn't explore this possibility further yet as this is suboptimal and I ran out of R&D time dedicated to this issue.

Any help would be very appreciated.

EvilVir avatar Apr 17 '25 02:04 EvilVir

Hi,

I’m not sure I understand, so my answer may be off-topic (let me know if it is the case). You need to reference MrAdvice package everywhere it is used (in each assembly where you apply advices). Because it has a build task, this is required, otherwise it won’t weave after build (and yes, it weaves in obj directory, not bin).

picrap avatar Apr 18 '25 14:04 picrap