172
172
<!-- ProjectReference -->
173
173
@foreach ( var dep in @Model .NuGetDependencies ) {
174
174
if (dep .IsProjectReference ) {
175
- < ProjectReference Include = " ..\. .\g enerated\@ (dep.MavenArtifact.MavenGroupId).@(dep.MavenArtifact.MavenArtifactId)\@ (dep.MavenArtifact.MavenGroupId).@(dep.MavenArtifact.MavenArtifactId).csproj" PrivateAssets = " none" / >
176
-
175
+ < ProjectReference Include = " ..\. .\g enerated\@ (dep.MavenArtifact.MavenGroupId).@(dep.MavenArtifact.MavenArtifactId)\@ (dep.MavenArtifact.MavenGroupId).@(dep.MavenArtifact.MavenArtifactId).csproj" PrivateAssets = " none" PackageVersion = " @GetProjectVersionString(dep.MavenArtifact.MavenArtifactVersion, dep.NuGetVersion)" / >
177
176
}
178
177
}
179
178
</ItemGroup >
183
182
<!-- PackageReference -->
184
183
@foreach ( var dep in @Model .NuGetDependencies ) {
185
184
if (! dep .IsProjectReference ) {
186
- < PackageReference Include = " @(dep.NuGetPackageId)" Version = " @( dep.NuGetVersion)" PrivateAssets = " none" / >
185
+ < PackageReference Include = " @(dep.NuGetPackageId)" Version = " @GetVersionString(dep.MavenArtifact.MavenArtifactVersion, dep.NuGetVersion)" PrivateAssets = " none" / >
187
186
}
188
187
}
189
188
</ItemGroup >
204
203
< / PropertyGroup >
205
204
}
206
205
206
+ @{
207
+ string GetProjectVersionString (string mavenVersion , string nugetVersion )
208
+ {
209
+ var adjusted_string = GetVersionString (mavenVersion , nugetVersion );
210
+
211
+ // If nothing changed, return empty string
212
+ if (adjusted_string == nugetVersion )
213
+ return null ;
214
+
215
+ return adjusted_string ;
216
+ }
217
+
218
+ string GetVersionString (string mavenVersion , string nugetVersion )
219
+ {
220
+ // If this isn't an exact version we don't use this code
221
+ if (! mavenVersion .StartsWith ('[' ) || ! mavenVersion .EndsWith (']' ) || mavenVersion .Contains (',' ))
222
+ return nugetVersion ;
223
+
224
+ // An exact version is requested like "1.2.0", however we want to let the revision (4th NuGet number) float,
225
+ // so that our updates that don't change the Java artifact can still be used.
226
+ // That is, if the POM specifies "1.2.0" and the dependency NuGet is already "1.2.0.4", we want to allow:
227
+ // 1.2.0.4 >= x < 1.2.1
228
+ // NuGet expresses that as "[1.2.0.4, 1.2.1)", so that's what we need to create.
229
+ var lower_bound = nugetVersion ;
230
+
231
+ var nuget_first = 0 ;
232
+ var nuget_second = 0 ;
233
+ var nuget_third = 0 ;
234
+
235
+ var nuget_parts = nugetVersion .Split ('.' );
236
+
237
+ if (nuget_parts .Length > 0 && int .TryParse (nuget_parts [0 ], out var p1 ))
238
+ nuget_first = p1 ;
239
+
240
+ if (nuget_parts .Length > 1 && int .TryParse (nuget_parts [1 ], out var p2 ))
241
+ nuget_second = p2 ;
242
+
243
+ if (nuget_parts .Length > 2 && int .TryParse (nuget_parts [2 ], out var p3 ))
244
+ nuget_third = p3 ;
245
+
246
+ // Bump the third number
247
+ nuget_third ++ ;
248
+
249
+ var upper_bound = $" {nuget_first }.{nuget_second }.{nuget_third }" ;
250
+
251
+ // Put it all together
252
+ return $" [{lower_bound }, {upper_bound })" ;
253
+ }
254
+ }
207
255
</Project >
0 commit comments