Validate ref project references (#56488)
authorEric StJohn <ericstj@microsoft.com>
Thu, 29 Jul 2021 00:45:49 +0000 (17:45 -0700)
committerGitHub <noreply@github.com>
Thu, 29 Jul 2021 00:45:49 +0000 (17:45 -0700)
* Validate that reference assembly projects only reference other reference assembly projects

* Permit ref->src reference if src project produces reference assembly

* Move target to references.targets

eng/references.targets

index 6adcba9..7cfb604 100644 (file)
     </ItemGroup>
   </Target>
 
+  <ItemDefinitionGroup>
+    <TargetPathWithTargetPlatformMoniker>
+      <IsReferenceAssembly>$(IsReferenceAssembly)</IsReferenceAssembly>
+    </TargetPathWithTargetPlatformMoniker>
+  </ItemDefinitionGroup>
+
+  <Target Name="ValidateReferenceAssemblyProjectReferences" Condition="'$(IsReferenceAssembly)' == 'true'" AfterTargets="ResolveReferences">
+    <Error Condition="'%(ReferencePath.ReferenceSourceTarget)' == 'ProjectReference' AND '%(ReferencePath.IsReferenceAssembly)' != 'true' AND '%(ReferencePath.ReferenceAssembly)' == ''"
+           Text="Reference assemblies must only reference other reference assemblies and '%(ReferencePath.ProjectReferenceOriginalItemSpec)' is not a reference assembly project and does not set 'ProduceReferenceAssembly'." />
+  </Target>
 </Project>