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

Add predefined variable ${fileDirBasename} #78316

Closed
kzhui125 opened this issue Aug 1, 2019 · 15 comments
Closed

Add predefined variable ${fileDirBasename} #78316

kzhui125 opened this issue Aug 1, 2019 · 15 comments
Assignees
Labels
author-verification-requested Issues potentially verifiable by issue author feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders tasks Task system issues verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@kzhui125
Copy link

kzhui125 commented Aug 1, 2019

Hello, I have some dotnet solutions opened as my root workspace.

For example:

${workspaceFolder}:
/home/username/dotnet-solution1

${file}:
/home/username/dotnet-solution1/project1/Program.cs
/home/username/dotnet-solution1/project2/Program.cs
/home/username/dotnet-solution1/project3/Program.cs
/home/username/dotnet-solution1/project4/Program.cs

When I open Program.cs or other cs file, I want press F5 to debug the corresponding project.

So I need this ${fileDirBasename} variable.

this is my expected lanunch config:

{
    "name": "Launch current project",
    "type": "coreclr",
    "request": "launch",
    "preLaunchTask": "build",
    "program": "${fileDirname}/bin/Debug/netcoreapp2.0/${fileDirBasename}.dll",
    "args": [],
    "cwd": "${fileDirname}",
    "stopAtEntry": false,
    "console": "internalConsole"
}

my expected build task:

{
    "label": "build",
    "command": "dotnet",
    "type": "process",
    "args": [
        "build",
        "${fileDirname}/${fileDirBasename}.csproj",
        "/property:GenerateFullPaths=true",
        "/consoleloggerparameters:NoSummary"
    ],
    "problemMatcher": "$msCompile"
}
@kzhui125 kzhui125 changed the title Add predefined variables ${fileDirBasename} Add predefined variable ${fileDirBasename} Aug 1, 2019
@isidorn
Copy link
Contributor

isidorn commented Aug 2, 2019

/findDuplicates

@isidorn
Copy link
Contributor

isidorn commented Aug 2, 2019

There might be already a feature request for this, unfortunetly I can not find it.
Leaving it open as a feature request for now and assigning to @alexr00

@isidorn isidorn added the feature-request Request for new features or functionality label Aug 2, 2019
@isidorn isidorn assigned alexr00 and unassigned isidorn Aug 2, 2019
@alexr00 alexr00 added this to the Backlog milestone Aug 2, 2019
@rioj7
Copy link

rioj7 commented Oct 3, 2019

for this project directory structure what is this variable different than ${relativeFileDirname}?

@kzhui125
Copy link
Author

kzhui125 commented Oct 3, 2019

@rioj7

consider this example:

/home/username/dotnet-solution1/dir1/project1/Program.cs

${relativeFileDirname} will be dir1/project1, I won't get "${fileDirname}/${fileDirBasename}.csproj" using ${relativeFileDirname}

@rioj7
Copy link

rioj7 commented Oct 8, 2019

@kzhui125 I have added this variable to the extension Command Variable v0.7.0.

In case you have a project structure

/home/username/dotnet-solution1/dir1/project1/Program.cs
/home/username/dotnet-solution1/dir1/project1/subdir1/tool.cs

And if your current file is tool.cs the launch or build will go bad.

Then you should use extension.commandvariable.file.fileAsKey

{
  "version": "2.0.0",
  "tasks": [
    {
        "label": "build",
        "command": "dotnet",
        "type": "process",
        "args": [
            "build",
            "${input:chooseFileBasename}/${input:chooseFileBasename}.csproj",
            "/property:GenerateFullPaths=true",
            "/consoleloggerparameters:NoSummary"
        ],
        "problemMatcher": "$msCompile"
    }
  ],
  "inputs": [
    {
      "id": "chooseFileBasename",
      "type": "command",
      "command": "extension.commandvariable.file.fileAsKey",
      "args": {
        "/project1/": "project1",
        "/project2/": "project2"
      }
    }
  ]
}

You need to make the key as specific as needed.

@alexr00
Copy link
Member

alexr00 commented Oct 8, 2019

Could you do ${fileDirname}/${relativeFileDirname}/${fileBasenameNoExtension}.csproj?

@alexr00 alexr00 added info-needed Issue requires more information from poster tasks Task system issues labels Oct 8, 2019
@kzhui125
Copy link
Author

kzhui125 commented Oct 8, 2019

@rioj7 thanks, I will have a try.

@alexr00

for example:
/Users/test/Documents/dotnet-solution1 opened as ${workspaceFolder}:
/Users/test/Documents/dotnet-solution1/dir1/project1/Program.cs opend as ${file}

my expected launch.json:

/Users/test/Documents/dotnet-solution1/dir1/project1/bin/Debug/netcoreapp2.0/project1.dll

my expected tasks.json:

/Users/test/Documents/dotnet-solution1/dir1/project1/project1.csproj

${fileDirname} will be /Users/test/Documents/dotnet-solution1/dir1/project1
${relativeFileDirname} will be dir1/project1
${fileBasenameNoExtension}.csproj will be Program.csproj

so ${fileDirname}/${relativeFileDirname}/${fileBasenameNoExtension}.csproj will be:

/Users/test/Documents/dotnet-solution1/dir1/project1/dir1/project1/Program.csproj

It's not as expected.

@alexr00
Copy link
Member

alexr00 commented Oct 9, 2019

${workspaceFolder}/${relativeFileDirname}/${fileBasenameNoExtension}.csproj?

@kzhui125
Copy link
Author

kzhui125 commented Oct 9, 2019

@alexr00

${fileBasenameNoExtension}.csproj will be Program.csproj

But project1.csproj is expected

@alexr00
Copy link
Member

alexr00 commented Oct 9, 2019

Ok. The feature request here is for a variable the resolves to the second to last segment of the current file's path.

@alexr00 alexr00 removed the info-needed Issue requires more information from poster label Oct 9, 2019
@alexr00 alexr00 modified the milestones: Backlog, November 2020 Nov 9, 2020
@alexr00
Copy link
Member

alexr00 commented Nov 9, 2020

The new variable is fileDirnameBasename

@alexr00 alexr00 closed this as completed Nov 9, 2020
alexr00 added a commit that referenced this issue Nov 9, 2020
@alexr00 alexr00 added author-verification-requested Issues potentially verifiable by issue author verification-needed Verification of issue is requested labels Nov 30, 2020
@github-actions github-actions bot removed the author-verification-requested Issues potentially verifiable by issue author label Nov 30, 2020
@github-actions
Copy link

Unable to locate closing commit in issue timeline. You can manually reference a commit by commenting \closedWith someCommitSha.

@alexr00
Copy link
Member

alexr00 commented Nov 30, 2020

\closedWith 551db7e

@alexr00 alexr00 added the author-verification-requested Issues potentially verifiable by issue author label Nov 30, 2020
@github-actions
Copy link

This bug has been fixed in to the latest release of VS Code Insiders!

@kzhui125, you can help us out by confirming things are working as expected in the latest Insiders release. If things look good, please leave a comment with the text /verified to let us know. If not, please ensure you're on version 0a80aac of Insiders (today's or later - you can use Help: About in the command palette to check), and leave a comment letting us know what isn't working as expected.

Happy Coding!

@aeschli
Copy link
Contributor

aeschli commented Dec 4, 2020

Verified with

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "echo",
            "type": "shell",
            "command": "echo",
            "args": ["${fileDirnameBasename}"],
            "problemMatcher": []
        }
    ]
}

@aeschli aeschli added the verified Verification succeeded label Dec 4, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Dec 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
author-verification-requested Issues potentially verifiable by issue author feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders tasks Task system issues verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

6 participants
@isidorn @aeschli @kzhui125 @alexr00 @rioj7 and others