Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions resources/netCore/GetBlazorManifestLocations.targets

This file was deleted.

33 changes: 0 additions & 33 deletions resources/netCore/GetProjectProperties.targets

This file was deleted.

24 changes: 11 additions & 13 deletions src/debugging/netSdk/NetSdkDebugHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,31 +111,29 @@ export class NetSdkDebugHelper extends NetCoreDebugHelper {
const ridOS = await normalizeOsToRidOs();
const ridArchitecture = await normalizeArchitectureToRidArchitecture();
const additionalProperties = composeArgs(
withNamedArg('/p:ContainerRuntimeIdentifier', `"${ridOS}-${ridArchitecture}"`, { assignValue: true }), // We have to pre-quote the file paths because we cannot simultaneously use `assignValue` and `shouldQuote`
withNamedArg('-p:ContainerRuntimeIdentifier', `"${ridOS}-${ridArchitecture}"`, { assignValue: true }), // We have to pre-quote the RID because we cannot simultaneously use `assignValue` and `shouldQuote`
)();
const resolvedAppProject = resolveVariables(debugConfiguration.netCore?.appProject, folder);

const projectInfo = await getNetCoreProjectInfo('GetProjectProperties', resolvedAppProject, additionalProperties);
const projectInfo = await getNetCoreProjectInfo(resolvedAppProject, additionalProperties);

if (projectInfo.length < 6 || !projectInfo[5]) {
if (!projectInfo.enableSdkContainerSupport) {
throw new Error(l10n.t("Your current project configuration or .NET SDK version doesn't support SDK Container build. Please choose a compatible project or update .NET SDK."));
}

const projectProperties: NetSdkProjectProperties = {
assemblyName: projectInfo[0],
targetFramework: projectInfo[1],
appOutput: projectInfo[2],
containerWorkingDirectory: projectInfo[3],
isSdkContainerSupportEnabled: projectInfo[4] === 'true',
imageName: projectInfo[5],
return {
assemblyName: projectInfo.assemblyName,
targetFramework: projectInfo.targetFrameworks[0],
Comment thread
bwateratmsft marked this conversation as resolved.
appOutput: projectInfo.assemblyRelativeOutputPath,
containerWorkingDirectory: projectInfo.assemblyContainerPath,
Comment thread
bwateratmsft marked this conversation as resolved.
isSdkContainerSupportEnabled: projectInfo.enableSdkContainerSupport,
imageName: projectInfo.imageName,
Comment thread
bwateratmsft marked this conversation as resolved.
};

return projectProperties;
}

private async normalizeAppOutput(unnormalizedContainerWorkingDirectory: string, isSdkContainerSupportEnabled: boolean): Promise<string> {
if (isSdkContainerSupportEnabled) {
return await getDockerOSType() === 'windows' // fourth is output path
return await getDockerOSType() === 'windows'
? path.win32.normalize(unnormalizedContainerWorkingDirectory)
: path.posix.normalize(unnormalizedContainerWorkingDirectory);
} else {
Expand Down
17 changes: 5 additions & 12 deletions src/debugging/netcore/NetCoreDebugHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,20 +204,13 @@ export class NetCoreDebugHelper implements DebugHelper {
}

protected async getProjectProperties(debugConfiguration: DockerDebugConfiguration): Promise<NetCoreProjectProperties> {
const projectInfo = await getNetCoreProjectInfo('GetProjectProperties', debugConfiguration.netCore?.appProject);
const projectInfo = await getNetCoreProjectInfo(debugConfiguration.netCore?.appProject);

if (projectInfo.length < 3) {
throw new Error(l10n.t('Unable to determine assembly output path.'));
}

// First line is assembly name, second is target framework, third+ are output path(s)
const projectProperties: NetCoreProjectProperties = {
assemblyName: projectInfo[0],
targetFramework: projectInfo[1],
appOutput: projectInfo[2]
return {
assemblyName: projectInfo.assemblyName,
targetFramework: projectInfo.targetFrameworks[0],
Comment thread
bwateratmsft marked this conversation as resolved.
appOutput: projectInfo.assemblyRelativeOutputPath,
};

return projectProperties;
}

private async acquireDebuggers(platformOS: PlatformOS): Promise<void> {
Expand Down
10 changes: 3 additions & 7 deletions src/scaffolding/wizard/netCore/NetCoreGatherInformationStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,14 @@ export class NetCoreGatherInformationStep extends GatherInformationStep<NetCoreS
public async prompt(wizardContext: NetCoreScaffoldingWizardContext): Promise<void> {
await this.ensureNetCoreBuildTasks(wizardContext);

const projectInfo = await getNetCoreProjectInfo('GetProjectProperties', wizardContext.artifact);

if (projectInfo.length < 2) {
throw new Error(vscode.l10n.t('Unable to determine project info for \'{0}\'', wizardContext.artifact));
}
const projectInfo = await getNetCoreProjectInfo(wizardContext.artifact);

if (!wizardContext.netCoreAssemblyName) {
wizardContext.netCoreAssemblyName = projectInfo[0]; // Line 1 is the assembly name including ".dll"
wizardContext.netCoreAssemblyName = projectInfo.assemblyName;
}

if (!wizardContext.netCoreRuntimeBaseImage || !wizardContext.netCoreSdkBaseImage) {
this.targetFramework = projectInfo[1]; // Line 2 is the <TargetFramework> value, or first item from <TargetFrameworks>
this.targetFramework = projectInfo.targetFrameworks[0];

const regexMatch = /net(coreapp)?([\d.]+)/i.exec(this.targetFramework);

Expand Down
69 changes: 7 additions & 62 deletions src/tasks/netcore/updateBlazorManifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,21 @@
*--------------------------------------------------------------------------------------------*/

import * as fse from 'fs-extra';
import * as path from 'path';
import { l10n } from 'vscode';
import * as xml2js from 'xml2js';
import { getNetCoreProjectInfo } from '../../utils/netCoreUtils';
import * as vscode from 'vscode';
import { getBlazorManifestInfo } from '../../utils/netCoreUtils';
import { pathNormalize } from '../../utils/pathNormalize';
import { PlatformOS } from '../../utils/platform';
import { DockerContainerVolume } from '../DockerRunTaskDefinitionBase';
import { DockerRunTaskDefinition } from "../DockerRunTaskProvider";
import { DockerRunTaskContext } from "../TaskHelper";

interface ContentRootAttributes {
BasePath: string;
Path: string;
}

interface ContentRoot {
$: ContentRootAttributes;
}

interface StaticWebAssets {
ContentRoot: ContentRoot[];
}

interface XmlManifest {
StaticWebAssets: StaticWebAssets;
}

interface JsonManifest {
ContentRoots: string[];
}

export async function updateBlazorManifest(context: DockerRunTaskContext, runDefinition: DockerRunTaskDefinition): Promise<void> {
const contents = await getNetCoreProjectInfo('GetBlazorManifestLocations', runDefinition.netCore.appProject);

if (contents.length < 2) {
throw new Error(l10n.t('Unable to determine Blazor manifest locations from output file.'));
}

await transformBlazorManifest(context, contents[0].trim(), contents[1].trim(), runDefinition.dockerRun.volumes, runDefinition.dockerRun.os);
const blazorInfo = await getBlazorManifestInfo(runDefinition.netCore.appProject);
await transformBlazorManifest(context, blazorInfo.inputManifestPath, blazorInfo.outputManifestPath, runDefinition.dockerRun.volumes, runDefinition.dockerRun.os);
}

async function transformBlazorManifest(context: DockerRunTaskContext, inputManifest: string, outputManifest: string, volumes: DockerContainerVolume[], os: PlatformOS): Promise<void> {
Expand All @@ -58,20 +34,16 @@ async function transformBlazorManifest(context: DockerRunTaskContext, inputManif

os = os || 'Linux';

context.terminal.writeOutputLine(l10n.t('Attempting to containerize Blazor static web assets manifest...'));
context.terminal.writeOutputLine(vscode.l10n.t('Attempting to containerize Blazor static web assets manifest...'));

if (path.extname(inputManifest) === '.json') {
await transformJsonBlazorManifest(inputManifest, outputManifest, volumes, os);
} else {
await transformXmlBlazorManifest(inputManifest, outputManifest, volumes, os);
}
await transformJsonBlazorManifest(inputManifest, outputManifest, volumes, os);
}

async function transformJsonBlazorManifest(inputManifest: string, outputManifest: string, volumes: DockerContainerVolume[], os: PlatformOS): Promise<void> {
const manifest = <JsonManifest>await fse.readJson(inputManifest);

if (!manifest?.ContentRoots) {
throw new Error(l10n.t('Failed to parse Blazor static web assets manifest.'));
throw new Error(vscode.l10n.t('Failed to parse Blazor static web assets manifest.'));
}

if (!Array.isArray(manifest.ContentRoots)) {
Expand All @@ -87,33 +59,6 @@ async function transformJsonBlazorManifest(inputManifest: string, outputManifest
await fse.utimes(outputManifest, 0, 0);
}

async function transformXmlBlazorManifest(inputManifest: string, outputManifest: string, volumes: DockerContainerVolume[], os: PlatformOS): Promise<void> {
const contents = (await fse.readFile(inputManifest)).toString();
const manifest = <XmlManifest>await xml2js.parseStringPromise(contents);

if (!manifest?.StaticWebAssets) {
throw new Error(l10n.t('Failed to parse Blazor static web assets manifest.'));
}

if (!Array.isArray(manifest.StaticWebAssets.ContentRoot)) {
return;
}

for (const contentRoot of manifest.StaticWebAssets.ContentRoot) {
if (contentRoot && contentRoot.$) {
contentRoot.$.Path = tryContainerizePath(contentRoot.$.Path, volumes, os);
}
}

const outputContents = (new xml2js.Builder()).buildObject(manifest);

// Write out a new manifest
await fse.writeFile(outputManifest, outputContents);

// Set the mtime to 1970 so that next time .NET builds, it will overwrite the output file
await fse.utimes(outputManifest, 0, 0);
}

function tryContainerizePath(oldPath: string, volumes: DockerContainerVolume[], os: PlatformOS): string {
const matchingVolume: DockerContainerVolume = volumes.find(v => oldPath.toLowerCase().startsWith(v.localPath.toLowerCase()));

Expand Down
Loading