Skip to content

Commit 07bc69b

Browse files
fix: exclude assemblies for nestandard for nuget v3 (#264)
1 parent 51ffe9b commit 07bc69b

File tree

8 files changed

+5894
-239
lines changed

8 files changed

+5894
-239
lines changed

lib/nuget-parser/index.ts

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -304,28 +304,39 @@ async function getResultsWithoutPublish(
304304
const parser = PARSERS['dotnet-core-v3'];
305305

306306
const projectFolder = projectPath ? path.dirname(projectPath) : safeRoot;
307-
const { sdkVersion, sdkPath } = await extractSdkInfo(projectFolder);
308-
const localRuntimes = await dotnet.execute(
309-
['--list-runtimes'],
310-
projectFolder,
307+
308+
// Check if any target frameworks need runtime assembly overrides
309+
const needsRuntimeOverrides = decidedTargetFrameworks.some(
310+
(framework) =>
311+
!framework.includes('netstandard') && !framework.includes('netcoreapp'),
311312
);
312-
const runtimeVersion = findLatestMatchingVersion(localRuntimes, sdkVersion);
313+
313314
const overridesAssemblies: AssemblyVersions = {};
314315

315-
try {
316-
const overridesPath: string = `${path.dirname(sdkPath)}${PACKS_PATH}${runtimeVersion}/${PACKAGE_OVERRIDES_FILE}`;
317-
const overridesText: string = fs.readFileSync(overridesPath, 'utf-8');
318-
for (const pkg of overridesText.split('\n')) {
319-
if (pkg) {
320-
const [name, version] = pkg.split('|');
321-
// Trim any carriage return
322-
overridesAssemblies[name] = version.trim();
316+
// Only load runtime overrides if we have frameworks that need them (exclude netstandard and netcoreapp)
317+
if (needsRuntimeOverrides) {
318+
const { sdkVersion, sdkPath } = await extractSdkInfo(projectFolder);
319+
const localRuntimes = await dotnet.execute(
320+
['--list-runtimes'],
321+
projectFolder,
322+
);
323+
const runtimeVersion = findLatestMatchingVersion(localRuntimes, sdkVersion);
324+
325+
try {
326+
const overridesPath: string = `${path.dirname(sdkPath)}${PACKS_PATH}${runtimeVersion}/${PACKAGE_OVERRIDES_FILE}`;
327+
const overridesText: string = fs.readFileSync(overridesPath, 'utf-8');
328+
for (const pkg of overridesText.split('\n')) {
329+
if (pkg) {
330+
const [name, version] = pkg.split('|');
331+
// Trim any carriage return
332+
overridesAssemblies[name] = version.trim();
333+
}
323334
}
335+
} catch (err) {
336+
throw new FileNotProcessableError(
337+
`Failed to read PackageOverrides.txt, error: ${err}`,
338+
);
324339
}
325-
} catch (err) {
326-
throw new FileNotProcessableError(
327-
`Failed to read PackageOverrides.txt, error: ${err}`,
328-
);
329340
}
330341

331342
// Loop through all TargetFrameworks supplied and generate a dependency graph for each.
@@ -345,9 +356,14 @@ async function getResultsWithoutPublish(
345356

346357
const overrides: Overrides = {
347358
overridesAssemblies,
348-
overrideVersion: targetFrameworkInfo.Version.split('.')
349-
.slice(0, -1)
350-
.join('.'),
359+
// .NET Standard and .NET Core App frameworks don't need runtime assembly overrides
360+
// as they don't provide specific runtime assembly information that can be read more precisely
361+
// than what's available in the project.assets.json file.
362+
overrideVersion:
363+
decidedTargetFramework.includes('netstandard') ||
364+
decidedTargetFramework.includes('netcoreapp')
365+
? undefined
366+
: targetFrameworkInfo.Version.split('.').slice(0, -1).join('.'),
351367
};
352368

353369
let targetFramework = decidedTargetFramework;

lib/nuget-parser/parsers/dotnet-core-v3-parser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ function recursivelyPopulateNodes(
6767
// If we're looking at a runtime assembly version for self-contained dlls, overwrite the dependency version
6868
// we've found in the graph with those from the runtime assembly, as they take precedence.
6969
if (
70+
overrides.overrideVersion &&
7071
+actualResolvedVersion.split('.')[0] < 6 &&
7172
childName in overrides.overridesAssemblies &&
7273
+overrides.overridesAssemblies[childName].split('.')[0] < 6

lib/nuget-parser/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export interface DotnetCoreV2Result {
111111

112112
export type Overrides = {
113113
overridesAssemblies: AssemblyVersions;
114-
overrideVersion: string;
114+
overrideVersion: string | undefined;
115115
};
116116

117117
export type ResolvedPackagesMap = Record<

0 commit comments

Comments
 (0)