question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:12
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

6reactions
davkeancommented, Apr 7, 2020

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.

4reactions
jibbers42commented, May 30, 2021

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 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

NET Core .csproj Output Path not working correctly
The problem is that when I define "OutputPath" as "bin\Debug" (for Debug mode, for instance), Visual Studio builds the project and sets ...
Read more >
($TargetPath) is wrong - Developer Community
To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Lib.OutputFile).
Read more >
Change the build output directory - Visual Studio (Windows)
Find the Base output path for C#, and type in the path to generate output to (absolute or relative to the root project...
Read more >
Visual Studio: Copying files to Debug or Release folder
This article will examine usage of "Copy to Output Directory" options along with alternate options to copy files with the bulk done in...
Read more >
Copy NuGet Content Files to Output Directory on Build
After reproducing the issue, I narrowed it down to a problem copying template files to the project output directory on build. Because the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found