godotengine / godot-csharp-visualstudio

Godot C# extension for Visual Studio
MIT License
251 stars 31 forks source link

Extension Doesn't seem to be working in Godot 3.2.3RC4 #10

Open Alriightyman opened 4 years ago

Alriightyman commented 4 years ago

OS/device including version: Windows 10

Issue description:

  1. Installed Godot CSharp extension
  2. Create new project in Godot 3.2.3 RC4
  3. Add a Node into the Scene
  4. Attach new C# script.
  5. Visual Studio opens

Expected: Expected to see Play In Editor, Launch, or Attach

Actual: Only see the Project name and it will not launch instead throwing an error of A project with an Output Type of Class Library cannot be started directly

Screenshots of issue: image image image

NOTES This worked just fine when using RC3. My guess is that when RC4 upgraded to the csproj sdk format, it broke compatibility.

Xyotic commented 2 years ago

Addendum: Seems like "launchSettings.json" is the right thing to use... In your project, create a folder named "Properties" and place the file inside.

This is how it looks: grafik

Obviously, this doesn't do anything yet... But maybe we can use this somehow.

GeorgeS2019 commented 2 years ago

@Xyotic Please see if you could implement using your suggestion to make VS2022 to use commands to

Xyotic commented 2 years ago

It works in combination with @neikeq 's way of starting Godot. If you remove the "StartArguments" and move them into the "commandLineArgs" of the launchSettings.json file you can start your project with different arguments.

Looks like this:

{
  "profiles": {
    "Launch": {
      "commandName": "Project"
    },
    "PlayInEditor": {
      "commandName": "Project",
      "commandLineArgs": "--path [Path/to/godot/project]"
    }
  }
}

And in you .csproj:

<PropertyGroup>
    <StartAction>Program</StartAction>
    <StartProgram>[Path/to/Godot.exe]</StartProgram>
</PropertyGroup>

if you leave your commandLineArgs empty it just launches godot without a project.

Not sure if we can realize an "attach" functionality this way tho.

Edit: I think it should be possible that the extension creates the launchSettings.json and the entry in the .csproj for you

GeorgeS2019 commented 2 years ago

This PR implements a way to define the Godot.exe path and execute it in a reliable way than the previous StubProj. All it needs is to deliver the parameters for different scenarios of debugging. neikeq has different messaging system to capture the standard and errors outputs for display in VS2022

I think the PR or the one before capture the godot project path

Xyotic commented 2 years ago

The code to define the .exe path could be used to create the .csproj entry.

But other than that I think these two approches are too different to be useful for eachother.

I didn't try if my solution works with breakpoints tho. Will do that later. But according to this, it should work?

Currently, the way to debug C# in Godot 4 with Visual Studio is as I explained here:

Xyotic commented 2 years ago

Update: Using "StartAction" + "StartProgram" in .csproj in combination with launchSettings.json do hit breakpoints in 4.0.

The next steps would be to check if the extension can interrupt startup and get information from the launchSettings. Maybe via environment variables... This way we could implement an "attach" launch profile.

Xyotic commented 2 years ago

I did some more digging and tried to make the Csp sample work @azbay mentioned.

Like @neikeq, it didn't build out of the box, but I managed to make it build. Basically all you have to do is to update the nuget packages inside this sample project. If you go with the preview packages (which are pretty current and just got some new updates), you'll also have to change the target framework of the sample to 4.7.2

Now It should build. The extension seems to load (it hits the breakpoint inside the CustomDebugger.cs constructor), but it doesnt add the new "CustomDebugger" Debug option to the Godot project... I've also followed the instructions and did add the nuget to the godot project.

I think it has something todo with the nuget itself. Inside the "CpsExtension.Nuget.targets" the CpsExtensionDesignTimeTargetsPath uses a condition which cant be fullfilled. I tried to remove the condition but it also didnt show up the CustomDebugger...

Maybe someone else got more ideas?

GeorgeS2019 commented 2 years ago

But other than that I think these two approaches are too different to be useful for each other.

Can you clarify are you relying on StubProj? I could not figure out how the StubProj works by launching Godot.

However, the new CommandLine to launching Godot seems clear to follow.

What needs to be done is to connect the Godot VS2022 extension Messaging to receive the standard and error outputs of running an external command (e.g. Godot.exe). These are the information that help to communicate with VS2022 where are the error and what are the error messages.

Xyotic commented 2 years ago

@GeorgeS2019 I dont rely on StubProj. This workaround does only work with .net framework projects as far as I'm aware. Which isnt going to work since we moved to .net6

GeorgeS2019 commented 2 years ago

Is this well documented? There is an option which is not StubProj and the latest commandline?

Can u share the links I could follow this Third method?

Xyotic commented 2 years ago

Follow my findings I mentioned above. Basically you only need to add this:

 <PropertyGroup>
    <StartAction>Program</StartAction>
    <StartProgram>C:\Path\To\Godot.exe</StartProgram>
    <StartArguments>--path C:\Path\To\Godot\Project\</StartArguments>
  </PropertyGroup>

to your .csproj and you can start debugging. If you want to add the differen launch profiles you can setup the launchsettings.json.

But currently I'm more interested in getting the csp sample to work

Logopher commented 5 months ago

Improved with MSBuild properties (I defined GODOT_EXE as an environment variable):

  <PropertyGroup>
    <StartAction>Program</StartAction>
    <StartProgram>$(GODOT_EXE)</StartProgram>
    <StartArguments>--path "$(MSBuildProjectDirectory)"</StartArguments>
  </PropertyGroup>
GeorgeS2019 commented 5 months ago

This should be closed...Godot 3. Ask in disvord