sdk: Debugging for .NET Core does not calculate the output path correctly with TargetName

I’ve been using <TargetName>ActualOutputFileNameWithoutExtension</TargetName> as a good way to control the output filename independently from the assembly’s actual name. Once in a while, for style reasons, this is handy. Sometimes I’ll need a long namespace and matching assembly name containing the namespace, but the output file name looks kinda silly.

As @boriscallens discovered, when you try to debug, the executable path is not properly calculated and debugging does not start. I don’t know if he’s using the old or new csproj SDK, but I did discover an issue with the new project system:

I’ve always happened to use this in the new csproj and targeting .NET Framework, where the debug executable path is properly calculated. It’s when you target .NET Core that it stops working.

Runs and debugs as expected:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net47</TargetFramework>
    <OutputType>exe</OutputType>
    <TargetName>TestFilename</TargetName>
  </PropertyGroup>

</Project>

Does not run or debug, unless you remove the <TargetName>:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp11</TargetFramework>
    <OutputType>exe</OutputType>
    <TargetName>TestFilename</TargetName>
  </PropertyGroup>

</Project>

Specifically, my expectation would be that debugging would honor <TargetFileName> calculated in Microsoft.Common.CurrentVersion.targets.

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 12
  • Comments: 18 (7 by maintainers)

Commits related to this issue

Most upvoted comments

I looked into this, there’s SDK bugs here:

  1. The generated host exe does not respect TargetName
  2. The generated runtimeconfig and deps.json does not respect TargetName

image

Moving over to the SDK.

Here is a simpler set of steps to reproduce the issue, but for running instead of debugging - hopefully the same fix for both.

==> dotnet --version 
5.0.300

==> dotnet new console -o TargetNameIssue
The template "Console Application" was created successfully.
...

==> cd TargetNameIssue

==> dotnet run
Hello World!

Edit TargetNameIssue.csproj and add <TargetName>CustomName</TargetName> within the ProperyGroup section.

==> dotnet run
The application to execute does not exist: '/home/jibbers42/code/testbeds/TargetNameIssue/bin/Debug/net5.0
/TargetNameIssue.dll'.

==> ls bin/Debug/net5.0/
CustomName.dll  ref              TargetNameIssue.deps.json               TargetNameIssue.runtimeconfig.json
CustomName.pdb  TargetNameIssue  TargetNameIssue.runtimeconfig.dev.json

It would be great to see a fix released for this issue 🙂

Any chance of getting some love on this issue? Repro steps are well documented, and it’s been a few months. The StackOverflow link in the original report has some more info on motivation.

Repro Steps:

  1. File, New Project
  2. Select ‘Windows Forms App (.Net Framework)’ from C# tree
  3. Name project ‘DebugExeIssue’
  4. Hit OK
  5. From ‘Build’ menu, select ‘Configuration Manager’
  6. Select ‘<New…>’ from Configuration dropdown
  7. Type in ‘Debug_newname’ and select ‘Debug’ from ‘Copy settings from:’ dropdown. Hit OK
  8. In Solution Explorer, Right Click on ‘DebugEXEIssue’ project node.
  9. Select ‘Properies’
  10. Click on ‘Build’ on the Project Properties window.
  11. Change ‘Configuration’ to ‘Debug_newname’
  12. In ‘Conditional compaliation symbols:’ texbox, add symbol ‘Debug_newname’
  13. Click ‘Save’ button
  14. In Solution Explorer, Right Click on ‘DebugEXEIssue’ project node.
  15. Select ‘Open Folder in File Explorer’
  16. Open ‘DebugEXEIssue.csproj’ in Notepad
  17. Locate line ‘<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_newname|AnyCPU'">’
  18. Hit the <enter> key to add a new line
  19. Add Property ‘<AssemblyName>Debug_newname</AssemblyName>’
  20. Save file and exit notepad
  21. Click ‘Reload All’ on ‘File Modification Detected’ messagebox in Visual Studio
  22. Press ‘F5’ to start debugging session

Expected:

Visual Studio will attach debugger to Debug_newname.exe and debugging session will start

Actual:

Visual Studio is unable to attach debugger to Debugnewname.exe because it is looking for DebugEXEIssue.exe.

The value in the ‘AssemblyName’ on the project properties is not updated based on the active configuration set in the Configuration manager.

It’s not exactly clear what fails; to route this to the correct component - can you fill out the following:

Repro Steps:

Expected:

Actual: