|
79 | 79 | <!-- NuGet Package Config ============================================ --> |
80 | 80 | <!-- Pack design notes: ./sqlclient-dotnet-pack.md --> |
81 | 81 | <PropertyGroup> |
| 82 | + |
| 83 | + <!-- Spec and proj paths. --> |
82 | 84 | <SqlClientPackNuspecTemplatePath Condition="'$(SqlClientPackNuspecTemplatePath)' == ''">$(RepoRoot)tools/specs/Microsoft.Data.SqlClient.nuspec</SqlClientPackNuspecTemplatePath> |
83 | 85 | <SqlClientPackNuspecGeneratedPath Condition="'$(SqlClientPackNuspecGeneratedPath)' == ''">$(BaseIntermediateOutputPath)Microsoft.Data.SqlClient.pack.nuspec</SqlClientPackNuspecGeneratedPath> |
| 86 | + <AbstractionsProjectPath>$(RepoRoot)/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/Abstractions.csproj</AbstractionsProjectPath> |
| 87 | + <LoggingProjectPath>$(RepoRoot)/src/Microsoft.Data.SqlClient.Internal/Logging/src/Logging.csproj</LoggingProjectPath> |
84 | 88 |
|
85 | | - <NuspecVersion Condition="'$(NuspecVersion)' == ''">$(Version)</NuspecVersion> |
| 89 | + <!-- Properties used by dotnet pack. --> |
86 | 90 | <NuspecFile Condition="'$(NuspecFile)' == ''">$(SqlClientPackNuspecTemplatePath)</NuspecFile> |
87 | 91 | <NuspecBasePath Condition="'$(NuspecBasePath)' == ''">$([System.IO.Path]::GetDirectoryName('$(SqlClientPackNuspecTemplatePath)'))</NuspecBasePath> |
| 92 | + <NuspecVersion Condition="'$(NuspecVersion)' == ''">$(Version)</NuspecVersion> |
| 93 | + <NuspecProperties Condition="'$(NuspecProperties)' == ''">COMMITID=$(CommitId);Configuration=$(Configuration);ReferenceType=$(ReferenceType)</NuspecProperties> |
88 | 94 | <IncludeSymbols Condition="'$(IncludeSymbols)' == ''">true</IncludeSymbols> |
89 | 95 | <SymbolPackageFormat Condition="'$(SymbolPackageFormat)' == ''">snupkg</SymbolPackageFormat> |
90 | 96 | <SuppressDependenciesWhenPacking Condition="'$(SuppressDependenciesWhenPacking)' == ''">true</SuppressDependenciesWhenPacking> |
91 | | - |
92 | | - <NuspecProperties Condition="'$(NuspecProperties)' == ''">COMMITID=$(CommitId);Configuration=$(Configuration);ReferenceType=$(ReferenceType)</NuspecProperties> |
93 | 97 | </PropertyGroup> |
94 | 98 |
|
95 | 99 | <!-- |
96 | 100 | SDK pack does not reliably substitute dependency version tokens in this nuspec flow. |
97 | 101 | We materialize those dependency versions into an intermediate nuspec before PackTask runs. |
| 102 | +
|
| 103 | + Why an intermediate nuspec is generated: |
| 104 | + * The source nuspec keeps dependency versions as tokens to stay template-driven. |
| 105 | + * During SDK-style packing, dependency token substitution is not consistently applied in this flow. |
| 106 | + * Expanding tokens up front guarantees deterministic dependency versions in the final package metadata. |
| 107 | +
|
| 108 | + Why sibling package versions are evaluated here: |
| 109 | + * Pack entrypoints may call this project directly and omit Abstractions/Logging version overrides. |
| 110 | + * Those versions must still align with sibling projects' versioning rules (BuildNumber/BuildSuffix and defaults). |
| 111 | + * Querying each sibling project for its computed package version preserves a single source of version truth. |
98 | 112 | --> |
99 | 113 | <Target Name="PrepareSqlClientPackNuspec" |
100 | 114 | BeforeTargets="GenerateNuspec" |
101 | 115 | Condition="'$(NuspecFile)' == '$(SqlClientPackNuspecTemplatePath)'"> |
102 | | - <Error Text="PrepareSqlClientPackNuspec requires AbstractionsPackageVersion. Specify -p:AbstractionsPackageVersion=<version> (or -p:PackageVersionAbstractions=<version> when invoking build.proj)." |
103 | | - Condition="'$(AbstractionsPackageVersion)' == ''" /> |
104 | | - <Error Text="PrepareSqlClientPackNuspec requires LoggingPackageVersion. Specify -p:LoggingPackageVersion=<version> (or -p:PackageVersionLogging=<version> when invoking build.proj)." |
105 | | - Condition="'$(LoggingPackageVersion)' == ''" /> |
106 | | - <Error Text="PrepareSqlClientPackNuspec requires NuspecVersion. Specify -p:NuspecVersion=<version>." |
107 | | - Condition="'$(NuspecVersion)' == ''" /> |
108 | 116 |
|
| 117 | + <!-- Calculate AbstractionsPackageVersion if not already set. --> |
| 118 | + <PropertyGroup Condition="'$(AbstractionsPackageVersion)' == ''"> |
| 119 | + <GetAbstractionsPackageVersionCommand> |
| 120 | + "$(DOTNET_HOST_PATH)" msbuild "$(AbstractionsProjectPath)" |
| 121 | + -nologo |
| 122 | + -verbosity:quiet |
| 123 | + -getProperty:AbstractionsPackageVersion |
| 124 | + -p:BuildNumber=$(BuildNumber) |
| 125 | + -p:BuildSuffix=$(BuildSuffix) |
| 126 | + </GetAbstractionsPackageVersionCommand> |
| 127 | + <GetAbstractionsPackageVersionCommand>$([System.Text.RegularExpressions.Regex]::Replace($(GetAbstractionsPackageVersionCommand), "\s+", " "))</GetAbstractionsPackageVersionCommand> |
| 128 | + </PropertyGroup> |
| 129 | + <Exec ConsoleToMsBuild="true" Command="$(GetAbstractionsPackageVersionCommand)" |
| 130 | + Condition="'$(AbstractionsPackageVersion)' == ''"> |
| 131 | + <Output TaskParameter="ConsoleOutput" PropertyName="AbstractionsPackageVersion" /> |
| 132 | + </Exec> |
| 133 | + <PropertyGroup Condition="'$(GetAbstractionsPackageVersionCommand)' != ''"> |
| 134 | + <AbstractionsPackageVersion>$([System.Text.RegularExpressions.Regex]::Replace($(AbstractionsPackageVersion), "\s", ""))</AbstractionsPackageVersion> |
| 135 | + </PropertyGroup> |
| 136 | + |
| 137 | + <!-- Calculate LoggingPackageVersion if not already set. --> |
| 138 | + <PropertyGroup Condition="'$(LoggingPackageVersion)' == ''"> |
| 139 | + <GetLoggingPackageVersionCommand> |
| 140 | + "$(DOTNET_HOST_PATH)" msbuild "$(LoggingProjectPath)" |
| 141 | + -nologo |
| 142 | + -verbosity:quiet |
| 143 | + -getProperty:LoggingPackageVersion |
| 144 | + -p:BuildNumber=$(BuildNumber) |
| 145 | + -p:BuildSuffix=$(BuildSuffix) |
| 146 | + </GetLoggingPackageVersionCommand> |
| 147 | + <GetLoggingPackageVersionCommand>$([System.Text.RegularExpressions.Regex]::Replace($(GetLoggingPackageVersionCommand), "\s+", " "))</GetLoggingPackageVersionCommand> |
| 148 | + </PropertyGroup> |
| 149 | + <Exec ConsoleToMsBuild="true" Command="$(GetLoggingPackageVersionCommand)" |
| 150 | + Condition="'$(LoggingPackageVersion)' == ''"> |
| 151 | + <Output TaskParameter="ConsoleOutput" PropertyName="LoggingPackageVersion" /> |
| 152 | + </Exec> |
| 153 | + <PropertyGroup Condition="'$(GetLoggingPackageVersionCommand)' != ''"> |
| 154 | + <LoggingPackageVersion>$([System.Text.RegularExpressions.Regex]::Replace($(LoggingPackageVersion), "\s", ""))</LoggingPackageVersion> |
| 155 | + </PropertyGroup> |
| 156 | + |
| 157 | + <!-- Expand the SqlClientPackNuspec template with the computed package versions. --> |
109 | 158 | <PropertyGroup> |
110 | 159 | <_SqlClientPackNuspecExpandedText>$([System.IO.File]::ReadAllText('$(SqlClientPackNuspecTemplatePath)').Replace('$AbstractionsPackageVersion$','$(AbstractionsPackageVersion)').Replace('$LoggingPackageVersion$','$(LoggingPackageVersion)').Replace('$NuspecVersion$','$(NuspecVersion)'))</_SqlClientPackNuspecExpandedText> |
111 | 160 | </PropertyGroup> |
112 | | - |
113 | 161 | <WriteLinesToFile File="$(SqlClientPackNuspecGeneratedPath)" |
114 | 162 | Lines="$(_SqlClientPackNuspecExpandedText)" |
115 | 163 | Overwrite="true" /> |
116 | 164 |
|
| 165 | + <!-- Set the NuspecFile property to the generated nuspec file. --> |
117 | 166 | <PropertyGroup> |
118 | 167 | <NuspecFile>$(SqlClientPackNuspecGeneratedPath)</NuspecFile> |
119 | 168 | </PropertyGroup> |
|
158 | 207 | <!-- References ====================================================== --> |
159 | 208 | <!-- Reference to Abstractions --> |
160 | 209 | <ItemGroup> |
161 | | - <ProjectReference Include="$(RepoRoot)/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/Abstractions.csproj" |
| 210 | + <ProjectReference Include="$(AbstractionsProjectPath)" |
162 | 211 | Condition="'$(ReferenceType)' != 'Package'" /> |
163 | 212 | <PackageReference Include="Microsoft.Data.SqlClient.Extensions.Abstractions" |
164 | 213 | Condition="'$(ReferenceType)' == 'Package'" /> |
165 | 214 | </ItemGroup> |
166 | 215 |
|
167 | 216 | <!-- Reference to Logging --> |
168 | 217 | <ItemGroup> |
169 | | - <ProjectReference Include="$(RepoRoot)/src/Microsoft.Data.SqlClient.Internal/Logging/src/Logging.csproj" |
| 218 | + <ProjectReference Include="$(LoggingProjectPath)" |
170 | 219 | Condition="'$(ReferenceType)' != 'Package'" /> |
171 | 220 | <PackageReference Include="Microsoft.Data.SqlClient.Internal.Logging" |
172 | 221 | Condition="'$(ReferenceType)' == 'Package'" /> |
|
0 commit comments