Custom Task and access to GeneratePathProperty create property from PackageReference element #8269
-
I'm writing a custom task for MSBuild to help automate configuration of Source Generators. I can get the PackageReference list and there are metadata on it. However it doesn't really give me any hint on the location of the assembly for the package. For example for the FullPath it gives me "C:\PATH_TO_PRJECT\PACKAGE_NAME" which doesn't point to anything. So I use the GeneratePathProperty="true" on the PackageReference element, expecting a property with nomenclature "PkgSome_Assembly_Name" having the value of the path to the package to be created. However, there's no such property present when I retrieve all the evaluated properties out of the Project. Anyone can help on this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Does your custom task get items as parameters from a target, or does it use the MSBuild API to load and evaluate a second instance of the project? I'd normally expect the former, but the way you "retrieve all the evaluated properties out of the Project" makes me suspect the latter. Are you trying to locate analyzer assemblies (including source generators) or reference assemblies? In Microsoft.CSharp.Core.targets, the CoreCompile target passes https://source.dot.net/ shows that the FindReferenceAssembliesForReferences target in Microsoft.Common.CurrentVersion.targets creates ReferencePathWithRefAssemblies items from ReferencePath items. msbuild/src/Tasks/Microsoft.Common.CurrentVersion.targets Lines 2390 to 2396 in 2badb37 The ResolveReferences target returns the ReferencePath items, so if you make your custom target depend on that, I think the ReferencePath items should have been created by then, and the target could pass them to your custom task. msbuild/src/Tasks/Microsoft.Common.CurrentVersion.targets Lines 1470 to 1473 in 2badb37 |
Beta Was this translation helpful? Give feedback.
Does your custom task get items as parameters from a target, or does it use the MSBuild API to load and evaluate a second instance of the project? I'd normally expect the former, but the way you "retrieve all the evaluated properties out of the Project" makes me suspect the latter.
Are you trying to locate analyzer assemblies (including source generators) or reference assemblies?
In Microsoft.CSharp.Core.targets, the CoreCompile target passes
References="@(ReferencePathWithRefAssemblies)"
andAnalyzers="@(Analyzer)"
to the Csc task, so these include the DLLs from NuGet packages.https://github.com/dotnet/roslyn/blob/15b43b33901c88f68ef43f8314b5a2457716780d/src/Compilers/Core/MSBuildTask/M…