Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support building launch assets for NET6-NET9 projects #4349

Merged
merged 2 commits into from
Jan 15, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class AssetGenerator {
const startupProjectDir = path.dirname(this.startupProject.Path);
const relativeProjectDir = path.join('${workspaceFolder}', path.relative(this.workspaceFolder.uri.fsPath, startupProjectDir));
const configurationName = 'Debug';
const targetFramework = protocol.findNetCoreAppTargetFramework(this.startupProject) ?? protocol.findNet5TargetFramework(this.startupProject);
const targetFramework = protocol.findNetCoreTargetFramework(this.startupProject);
const result = path.join(relativeProjectDir, `bin/${configurationName}/${targetFramework.ShortName}/${this.startupProject.AssemblyName}.dll`);
return result;
}
Expand Down
28 changes: 16 additions & 12 deletions src/omnisharp/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -865,27 +865,32 @@ export function findNetFrameworkTargetFramework(project: MSBuildProject): Target
return project.TargetFrameworks.find(tf => regexp.test(tf.ShortName));
}

export function findNet5TargetFramework(project: MSBuildProject): TargetFramework {
const targetFramework = project.TargetFrameworks.find(tf => tf.ShortName.startsWith('net5'));
// Temprorary workaround until changes to support the net5.0 TFM is settled. Some NuGet
// builds report the shortname as net50.
if (targetFramework !== undefined) {
targetFramework.ShortName = "net5.0";
}
return targetFramework;
export function findNetCoreTargetFramework(project: MSBuildProject): TargetFramework {
return findNetCoreAppTargetFramework(project) ?? findModernNetFrameworkTargetFramework(project);
}

export function findNetCoreAppTargetFramework(project: MSBuildProject): TargetFramework {
return project.TargetFrameworks.find(tf => tf.ShortName.startsWith('netcoreapp'));
}

export function findModernNetFrameworkTargetFramework(project: MSBuildProject): TargetFramework {
let regexp = new RegExp('^net[5-9]');
const targetFramework = project.TargetFrameworks.find(tf => regexp.test(tf.ShortName));

// Shortname is being reported as net50 instead of net5.0
if (targetFramework !== undefined && targetFramework.ShortName.charAt(4) !== ".") {
targetFramework.ShortName = targetFramework.ShortName.substr(0, 4) + "." + targetFramework.ShortName.substr(4);
}

return targetFramework;
}

export function findNetStandardTargetFramework(project: MSBuildProject): TargetFramework {
return project.TargetFrameworks.find(tf => tf.ShortName.startsWith('netstandard'));
}

export function isDotNetCoreProject(project: MSBuildProject): Boolean {
return findNet5TargetFramework(project) !== undefined ||
findNetCoreAppTargetFramework(project) !== undefined ||
return findNetCoreTargetFramework(project) !== undefined ||
findNetStandardTargetFramework(project) !== undefined ||
findNetFrameworkTargetFramework(project) !== undefined;
}
Expand Down Expand Up @@ -928,8 +933,7 @@ export function findExecutableMSBuildProjects(projects: MSBuildProject[]) {
let result: MSBuildProject[] = [];

projects.forEach(project => {
const projectIsNotNetFramework = findNetCoreAppTargetFramework(project) !== undefined
|| findNet5TargetFramework(project) !== undefined
const projectIsNotNetFramework = findNetCoreTargetFramework(project) !== undefined
|| project.IsBlazorWebAssemblyStandalone;

if (project.IsExe && projectIsNotNetFramework) {
Expand Down
40 changes: 29 additions & 11 deletions test/featureTests/assets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,35 @@ suite("Asset generation: csproj", () => {
segments.should.deep.equal(['${workspaceFolder}', 'bin', 'Debug', 'netcoreapp1.0', 'testApp.dll']);
});

test("Create launch.json for NET 5 project opened in workspace", () => {
let rootPath = path.resolve('testRoot');
let info = createMSBuildWorkspaceInformation(path.join(rootPath, 'testApp.csproj'), 'testApp', 'net5.0', /*isExe*/ true);
let generator = new AssetGenerator(info, createMockWorkspaceFolder(rootPath));
generator.setStartupProject(0);
let launchJson = parse(generator.createLaunchJsonConfigurations(ProgramLaunchType.Console), undefined, { disallowComments: true });
let programPath = launchJson[0].program;

// ${workspaceFolder}/bin/Debug/net5.0/testApp.dll
let segments = programPath.split(path.posix.sep);
segments.should.deep.equal(['${workspaceFolder}', 'bin', 'Debug', 'net5.0', 'testApp.dll']);
[5, 6, 7, 8, 9].forEach(version => {
const shortName = `net${version}.0`;
const alternameShortName = `net${version}0`;

test(`Create launch.json for NET ${version} project opened in workspace with shortname '${shortName}'`, () => {
let rootPath = path.resolve('testRoot');
let info = createMSBuildWorkspaceInformation(path.join(rootPath, 'testApp.csproj'), 'testApp', shortName, /*isExe*/ true);
let generator = new AssetGenerator(info, createMockWorkspaceFolder(rootPath));
generator.setStartupProject(0);
let launchJson = parse(generator.createLaunchJsonConfigurations(ProgramLaunchType.Console), undefined, { disallowComments: true });
let programPath = launchJson[0].program;

// ${workspaceFolder}/bin/Debug/net#.0/testApp.dll
let segments = programPath.split(path.posix.sep);
segments.should.deep.equal(['${workspaceFolder}', 'bin', 'Debug', shortName, 'testApp.dll']);
});

test(`Create launch.json for NET ${version} project opened in workspace with shortname '${alternameShortName}'`, () => {
let rootPath = path.resolve('testRoot');
let info = createMSBuildWorkspaceInformation(path.join(rootPath, 'testApp.csproj'), 'testApp', alternameShortName, /*isExe*/ true);
let generator = new AssetGenerator(info, createMockWorkspaceFolder(rootPath));
generator.setStartupProject(0);
let launchJson = parse(generator.createLaunchJsonConfigurations(ProgramLaunchType.Console), undefined, { disallowComments: true });
let programPath = launchJson[0].program;

// ${workspaceFolder}/bin/Debug/net#.0/testApp.dll
let segments = programPath.split(path.posix.sep);
segments.should.deep.equal(['${workspaceFolder}', 'bin', 'Debug', shortName, 'testApp.dll']);
});
});

test("Create launch.json for nested project opened in workspace", () => {
Expand Down