Make changes to reference assembly rerun compile (#46999)
authorEric StJohn <ericstj@microsoft.com>
Mon, 18 Jan 2021 23:17:06 +0000 (15:17 -0800)
committerGitHub <noreply@github.com>
Mon, 18 Jan 2021 23:17:06 +0000 (00:17 +0100)
* Make changes to reference assembly rerun compile

* Make sure src project will build ref project

This ensures we'll catch incremental changes to reference assemblies

* Allow a project to specify its reference assembly

eng/resolveContract.targets
src/libraries/shims/Directory.Build.targets [new file with mode: 0644]

index 0608475..f41be68 100644 (file)
@@ -1,32 +1,22 @@
 <Project>
   <PropertyGroup>
-    <ContractDependencyPaths Condition="'$(DisableImplicitFrameworkReferences)' == 'true' and
-                                        '$(TargetFrameworkIdentifier)' == '.NETCoreApp'">$(MicrosoftNetCoreAppRefPackRefDir)</ContractDependencyPaths>
-    <!-- Use implementation referencepath if no contract tfm is set. -->
-    <ContractDependencyPaths Condition="'$(ContractDependencyPaths)' == ''">$(ContractDependencyPaths);@(ReferencePath->'%(RelativeDir)'->Distinct())</ContractDependencyPaths>
+    <!-- Use implementation referencepath if no contract dependency path is set.
+         This item transform is executed at the time this property is evaluated in the API Compat targets. -->
+    <ContractDependencyPaths Condition="'$(ContractDependencyPaths)' == ''">@(ReferencePath->'%(RelativeDir)'->Distinct())</ContractDependencyPaths>
   </PropertyGroup>
 
   <PropertyGroup Condition="'$(IsSourceProject)' == 'true'">
     <ContractProject Condition="'$(ContractProject)' == ''">$(LibrariesProjectRoot)$(MSBuildProjectName)\ref\$(MSBuildProjectName).csproj</ContractProject>
     <HasMatchingContract Condition="'$(HasMatchingContract)' == '' and Exists('$(ContractProject)')">true</HasMatchingContract>
-    <ContractAssemblyPath Condition="'$(ContractAssemblyPath)' == '' and
-                                     '$(TargetFrameworkIdentifier)' == '.NETCoreApp' and
-                                     $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '$(NETCoreAppCurrentVersion)'))">$(NetCoreAppCurrentRefPath)$(TargetFileName)</ContractAssemblyPath>
-    <_TargetFrameworkWithoutPlatform>$([System.Text.RegularExpressions.Regex]::Replace('$(TargetFramework)', '(-[^;]+)', ''))</_TargetFrameworkWithoutPlatform>
-    <ContractAssemblyPath Condition="'$(ContractAssemblyPath)' == ''">$([MSBuild]::NormalizePath('$(BaseOutputPath)', 'ref', '$(_TargetFrameworkWithoutPlatform)-$(Configuration)', '$(TargetFileName)'))</ContractAssemblyPath>
     <!-- Disable API compat if the project doesn't have reference assembly -->
     <RunApiCompat Condition="'$(HasMatchingContract)' != 'true'">false</RunApiCompat>
   </PropertyGroup>
 
-  <ItemGroup Condition="'$(HasMatchingContract)' == 'true'">
-    <ResolvedMatchingContract Condition="Exists('$(ContractAssemblyPath)')" Include="$(ContractAssemblyPath)" />
-    <!-- If the contract doesn't exist in the default contract output path add a project reference to the contract project to resolve -->
-    <ProjectReference Condition="'@(ResolvedMatchingContract)' == ''" Include="$(ContractProject)">
-      <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
-      <OutputItemType>ResolvedMatchingContract</OutputItemType>
-    </ProjectReference>
+  <ItemGroup Condition="'$(HasMatchingContract)' == 'true' and '$(ContractProject)' != '' and '@(ResolvedMatchingContract)' == ''">
+    <ProjectReference Include="$(ContractProject)" ReferenceOutputAssembly="false" OutputItemType="ResolvedMatchingContract" />
+    <!-- We aren't referencing the contract, but make sure it's considered as an input to Compile so that if it changes we rebuild and rerun API compat -->
+    <ProjectReference Include="$(ContractProject)" ReferenceOutputAssembly="false" OutputItemType="CustomAdditionalCompileInputs" />
   </ItemGroup>
-
   <!-- intentionally empty since we no longer need a target -->
   <Target Name="ResolveMatchingContract" />
 
diff --git a/src/libraries/shims/Directory.Build.targets b/src/libraries/shims/Directory.Build.targets
new file mode 100644 (file)
index 0000000..2974cea
--- /dev/null
@@ -0,0 +1,7 @@
+<Project>
+  <ItemGroup>
+    <ResolvedMatchingContract Include="$(ContractAssemblyPath)" />
+  </ItemGroup>
+
+  <Import Project="..\Directory.Build.targets" />
+</Project>