diff --git a/src/assets.ts b/src/assets.ts index 410a05b34..c09132029 100644 --- a/src/assets.ts +++ b/src/assets.ts @@ -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; } diff --git a/src/omnisharp/protocol.ts b/src/omnisharp/protocol.ts index 8cb6ebaf6..7fe3c74ec 100644 --- a/src/omnisharp/protocol.ts +++ b/src/omnisharp/protocol.ts @@ -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; } @@ -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) { diff --git a/test/featureTests/assets.test.ts b/test/featureTests/assets.test.ts index f83ab24e2..3a6608581 100644 --- a/test/featureTests/assets.test.ts +++ b/test/featureTests/assets.test.ts @@ -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", () => {