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 1 commit
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-6]');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of explicitly testing for '6', would it make any sense to change this to [0-9+] and then convert the number to a string and accept anything >= 50?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I would need to do additional filtering to exclude net[1-4], Maybe the simpler option is to check for net[5-9] which would buy us a few years.

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
13 changes: 13 additions & 0 deletions test/featureTests/assets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ suite("Asset generation: csproj", () => {
segments.should.deep.equal(['${workspaceFolder}', 'bin', 'Debug', 'net5.0', 'testApp.dll']);
});

test("Create launch.json for NET 6 project opened in workspace", () => {
let rootPath = path.resolve('testRoot');
let info = createMSBuildWorkspaceInformation(path.join(rootPath, 'testApp.csproj'), 'testApp', 'net60', /*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/net6.0/testApp.dll
let segments = programPath.split(path.posix.sep);
segments.should.deep.equal(['${workspaceFolder}', 'bin', 'Debug', 'net6.0', 'testApp.dll']);
});

test("Create launch.json for nested project opened in workspace", () => {
let rootPath = path.resolve('testRoot');
let info = createMSBuildWorkspaceInformation(path.join(rootPath, 'nested', 'testApp.csproj'), 'testApp', 'netcoreapp1.0');
Expand Down