[release/6.0] Ensure UserSecretsIdAttribute is added to assembly (#63423)
authorEric Erhardt <eric.erhardt@microsoft.com>
Fri, 7 Jan 2022 18:45:06 +0000 (12:45 -0600)
committerGitHub <noreply@github.com>
Fri, 7 Jan 2022 18:45:06 +0000 (10:45 -0800)
* [release/6.0] Ensure UserSecretsIdAttribute is added to assembly

When Microsoft.Extensions.Configuration.UserSecrets is referenced transitively, for example through Extensions.Hosting, the UserSecretsIdAttribute isn't getting added to the built assembly. This is because the logic is contained in a `build` folder which is excluded by the dependency from Extensions.Hosting.

The fix is to move the logic to `buildTransitive`, so it gets picked up by NuGet.

Note, we also need to service the Extensions.Hosting package so it references the new UserSecrets version by default.

Fix #63246

* Add a binding redirect in order to fix test failure on netfx.

src/libraries/Microsoft.Extensions.Configuration.UserSecrets/src/Microsoft.Extensions.Configuration.UserSecrets.csproj
src/libraries/Microsoft.Extensions.Configuration.UserSecrets/src/build/netstandard2.0/Microsoft.Extensions.Configuration.UserSecrets.props [deleted file]
src/libraries/Microsoft.Extensions.Configuration.UserSecrets/src/build/netstandard2.0/Microsoft.Extensions.Configuration.UserSecrets.targets [deleted file]
src/libraries/Microsoft.Extensions.Configuration.UserSecrets/src/buildTransitive/netstandard2.0/Microsoft.Extensions.Configuration.UserSecrets.props [new file with mode: 0644]
src/libraries/Microsoft.Extensions.Configuration.UserSecrets/src/buildTransitive/netstandard2.0/Microsoft.Extensions.Configuration.UserSecrets.targets [new file with mode: 0644]
src/libraries/Microsoft.Extensions.Hosting/Directory.Build.props
src/libraries/Microsoft.Extensions.Hosting/src/Microsoft.Extensions.Hosting.csproj
src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Microsoft.Extensions.Hosting.Unit.Tests.csproj

index 3fda47281fe0f4aab5ec6acd084a52c09bc95631..659217f32d2152e6df3be8d581e17aa506677ca3 100644 (file)
@@ -16,8 +16,8 @@
   </ItemGroup>
 
   <ItemGroup>
-    <Content Include="build\netstandard2.0\$(MSBuildProjectName).props" PackagePath="%(Identity)" />
-    <Content Include="build\netstandard2.0\$(MSBuildProjectName).targets" PackagePath="%(Identity)" />
+    <Content Include="buildTransitive\netstandard2.0\$(MSBuildProjectName).props" PackagePath="%(Identity)" />
+    <Content Include="buildTransitive\netstandard2.0\$(MSBuildProjectName).targets" PackagePath="%(Identity)" />
   </ItemGroup>
 
 </Project>
diff --git a/src/libraries/Microsoft.Extensions.Configuration.UserSecrets/src/build/netstandard2.0/Microsoft.Extensions.Configuration.UserSecrets.props b/src/libraries/Microsoft.Extensions.Configuration.UserSecrets/src/build/netstandard2.0/Microsoft.Extensions.Configuration.UserSecrets.props
deleted file mode 100644 (file)
index 4de70a5..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-
-  <ItemGroup>
-    <!-- This capability represents the UserSecretsID + secrets.json approach to storing local user secrets. -->
-    <ProjectCapability Include="LocalUserSecrets" />
-  </ItemGroup>
-
-</Project>
diff --git a/src/libraries/Microsoft.Extensions.Configuration.UserSecrets/src/build/netstandard2.0/Microsoft.Extensions.Configuration.UserSecrets.targets b/src/libraries/Microsoft.Extensions.Configuration.UserSecrets/src/build/netstandard2.0/Microsoft.Extensions.Configuration.UserSecrets.targets
deleted file mode 100644 (file)
index f0f96dd..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-
-  <PropertyGroup>
-    <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
-    <GenerateUserSecretsAttribute Condition="'$(GenerateUserSecretsAttribute)'==''">true</GenerateUserSecretsAttribute>
-  </PropertyGroup>
-
-  <ItemGroup Condition=" '$(UserSecretsId)' != '' AND '$(GenerateUserSecretsAttribute)' != 'false' ">
-    <AssemblyAttribute Include="Microsoft.Extensions.Configuration.UserSecrets.UserSecretsIdAttribute">
-      <_Parameter1>$(UserSecretsId.Trim())</_Parameter1>
-    </AssemblyAttribute>
-  </ItemGroup>
-</Project>
diff --git a/src/libraries/Microsoft.Extensions.Configuration.UserSecrets/src/buildTransitive/netstandard2.0/Microsoft.Extensions.Configuration.UserSecrets.props b/src/libraries/Microsoft.Extensions.Configuration.UserSecrets/src/buildTransitive/netstandard2.0/Microsoft.Extensions.Configuration.UserSecrets.props
new file mode 100644 (file)
index 0000000..4de70a5
--- /dev/null
@@ -0,0 +1,8 @@
+<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+
+  <ItemGroup>
+    <!-- This capability represents the UserSecretsID + secrets.json approach to storing local user secrets. -->
+    <ProjectCapability Include="LocalUserSecrets" />
+  </ItemGroup>
+
+</Project>
diff --git a/src/libraries/Microsoft.Extensions.Configuration.UserSecrets/src/buildTransitive/netstandard2.0/Microsoft.Extensions.Configuration.UserSecrets.targets b/src/libraries/Microsoft.Extensions.Configuration.UserSecrets/src/buildTransitive/netstandard2.0/Microsoft.Extensions.Configuration.UserSecrets.targets
new file mode 100644 (file)
index 0000000..f0f96dd
--- /dev/null
@@ -0,0 +1,13 @@
+<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+
+  <PropertyGroup>
+    <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
+    <GenerateUserSecretsAttribute Condition="'$(GenerateUserSecretsAttribute)'==''">true</GenerateUserSecretsAttribute>
+  </PropertyGroup>
+
+  <ItemGroup Condition=" '$(UserSecretsId)' != '' AND '$(GenerateUserSecretsAttribute)' != 'false' ">
+    <AssemblyAttribute Include="Microsoft.Extensions.Configuration.UserSecrets.UserSecretsIdAttribute">
+      <_Parameter1>$(UserSecretsId.Trim())</_Parameter1>
+    </AssemblyAttribute>
+  </ItemGroup>
+</Project>
index 43dc3a2640bbaee9ce2f3cd1302ceb96eb71a1cd..207017db91b3d1cda15a804c2fa4a22e97d98292 100644 (file)
@@ -2,5 +2,6 @@
   <Import Project="..\Directory.Build.props" />
   <PropertyGroup>
     <IncludePlatformAttributes>true</IncludePlatformAttributes>
+    <ServicingVersion>1</ServicingVersion>
   </PropertyGroup>
 </Project>
index b868be57845e0c5d48a42acbb0cd4e34120bc30f..f80e9513f42411facbe2daa5349de88622e1d3b7 100644 (file)
@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
     <TargetFrameworks>$(NetCoreAppCurrent);netstandard2.0;netstandard2.1;net461</TargetFrameworks>
@@ -6,6 +6,8 @@
     <PackageDescription>Hosting and startup infrastructures for applications.</PackageDescription>
     <!-- Use targeting pack references instead of granular ones in the project file. -->
     <DisableImplicitAssemblyReferences>false</DisableImplicitAssemblyReferences>
+    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
+    <!-- ServicingVersion moved to ..\Directory.Build.props in order to share with test project. -->
   </PropertyGroup>
 
   <ItemGroup Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">
index ee0c814c41b3f02c9fbdc6e93db2f43681323120..babb650155cbfbc4329898e4bbcceb6cbac3dcbb 100644 (file)
     <ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Extensions.Hosting\src\Microsoft.Extensions.Hosting.csproj" />
   </ItemGroup>
 
+  <ItemGroup>
+    <!-- Workaround for https://github.com/dotnet/runtime/issues/63467 -->
+    <SuggestedBindingRedirects Include="Microsoft.Extensions.Hosting, Culture=neutral, PublicKeyToken=adb9793829ddae60"
+                               MaxVersion="$(MajorVersion).$(MinorVersion).0.$(ServicingVersion)" />
+  </ItemGroup>
+
 </Project>