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

Missing Launch.json Auto-Creation for dotnetcore classlib template #2703

Closed
parsalotfy opened this issue Nov 25, 2018 · 10 comments
Closed

Missing Launch.json Auto-Creation for dotnetcore classlib template #2703

parsalotfy opened this issue Nov 25, 2018 · 10 comments

Comments

@parsalotfy
Copy link

Environment data

dotnet --info output:
.NETCore SDK version 2.1.400
VSCode version 1.29.1 (latest in time of writing this)
CsharpExtension version 1.17.1
OS Windows x64

Steps to reproduce

All the problem is creating, building and debugging the dot net core class library.

Expected behavior

when I create a Console project using this command : dotnet new console -o A1 , the C# extension automatically create bin folder and ask me :

required assets to build and debug are missing from Console, Add them ?
image

.

and after clicking yes, the extension creates and configured launch.json and task.json for me :

image
and after pressing F5 , it compiles and builds successfully.
But ...

Actual behavior

But when I create class library using this command : dotnet new classlib -o A1
the extension does NOT show me any notification that ask me if I would like to add assets or not
I mean the extension does NOT create Launch.json and Task.json for me and clearly does not configure them.
image
.
When I press F5 the command palette asks me to select my environment and I click on .Net Core
Then it generates Launch.json for me BUT Wrongly and when I press F5 to build it , I get this Error :

Could not find the task 'build'

image

this is too annoying to have this behavior in this rich text editor and extension.
Thank you for your good Extension 🥇

@rchande
Copy link

rchande commented Nov 26, 2018

@akshita31 Can you take a look?

@gregg-miskelly
Copy link
Contributor

@parsalotfy Thanks for writing up such good steps. However, this is actually how things are designed to work.

The issue is this: if you have a class lib project, then that project isn't launchable by itself -- you would need to add another project, such as a console app, or ASP.NET app which referenced the class library if you wanted to launch the project.

The C# extension still offers debugging templates in this scenario because you might have some other executable which isn't a project in your workspace that you can use to launch a process which loads your class library (ex: something that loads your class library with reflection) and VS Code is designed around the idea that you can string together any tools you want. But in this scenario the C# extension has no idea how you want your scenario configured, so everything it outputs is very generic and you need to roll build tasks and configure launch.json yourself.

@parsalotfy
Copy link
Author

Thank you, I know the scenario is generic but I think it would be a good idea to have a default behavior for building the library.
any way , I write my Launch.json and Task.json here for those who have my problem because I was searching in google for hours and I did not come up with solution in the net.
thanks again 👍

My Launch.json configuration for building my class library with F5

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": ".NET Core Launch lib",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            "program": "${workspaceFolder}/lib/bin/Debug/netstandard2.0/lib.dll",
            "args": [],
            "cwd": "${workspaceFolder}/lib",
            "stopAtEntry": false,
            "console": "integratedTerminal"
        }
    ]
}


My Task.json configuration for building my class library with F5.

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "command": "dotnet",
            "type": "process",
            "group": "build",
            "args": ["build","${workspaceFolder}/lib"],
            "problemMatcher": "$msCompile"
        }
    ]
}

@gregg-miskelly
Copy link
Contributor

@parsalotfy to be clear: your launch.json doesn't look like it would work - that should just give you a cryptic error in your console like:

PS C:\scratch\cliclasslib> dotnet bin\Debug\netstandard2.0\cliclasslib.dll
A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\scratch\cliclasslib\bin\Debug\netstandard2.0\'.
Failed to run as a self-contained app. If this should be a framework-dependent app, add the C:\scratch\cliclasslib\bin\Debug\netstandard2.0\cliclasslib.runtimeconfig.json file specifying the appropriate framework.

@parsalotfy
Copy link
Author

parsalotfy commented Nov 26, 2018

yes exactly that gives me that error but I ignore it because my library builds in that way :-D

image

is there any Best solution ?!!
to have no error ?
thank you. 👍

@rchande
Copy link

rchande commented Dec 19, 2018

@gregg-miskelly We could offer to generate tasks.json but not launch.json for class libraries. What do you think?

@gregg-miskelly
Copy link
Contributor

Sounds reasonable to me.

@gregg-miskelly
Copy link
Contributor

@rchande I fixed things so we still don't automatically prompt to generate tasks.json, but if one explicitly asks for one by executing '.NET: Generate Assets for Build and Debug', we will create one.

Here was my thinking:

  • This is the first request we have had for supporting the feature
  • I could imagine some people might be annoyed at the prompt if folks are just trying to browse sources for their dll
  • I could also imagine some confusion if folks first created a class library, generated a build command for that, and then later added a launchable project. In this case, we would generate a launch.json, but not a tasks.json since one already exists with a 'build' command.

@rchande
Copy link

rchande commented Jan 7, 2019

@gregg-miskelly Sounds reasonable to me.

@alexanderdp
Copy link

OMFG why so much overhead and problems to have a simple extension work!
What a waste of time!
It's just easier to launch VS17/19 and test code in a new file or use dotnetfiddle.net to run quick code tests.
I was under the impression that VSCode extensions was supposed to be light weight and quick!

Thumbs down....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants