Scaffolding: Debugging scaffolding .net core

Created on 14 Mar 2017  Ā·  7Comments  Ā·  Source: dotnet/Scaffolding

From @ali-raza-iftikhar on https://github.com/prafullbhosale/EmptyControllerAndViewScaffolder/issues/1
What is the way to debug scaffolding?

Most helpful comment

@ali-raza-iftikhar, the below steps are what I use for debugging.
Let me know if you hit any issues with this.

Steps for debugging

  1. Add the above line of code in a place that is before where you want the first breakpoint.
while (!System.Diagnostics.Debugger.IsAttached){ }
  1. Build the packages (run ā€˜build /t:compile’ on the repo)
  2. Create a new web project (or use an existing one).
    a. Add a new NuGet.config file to point to the artifacts\build folder under the repo directory.
    b. Update the version numbers for the scaffolding packages in the project to pick up latest.
  3. Open Scaffolding solution in VS (another instance if project is open in VS) and add a break point.
  4. Scaffold from VS or command line.
  5. From scaffolding solution, attach debugger to dotnet.exe (there maybe multiple, but ususally this is the one on top of the list).
    a. Need to figure out if the code is in inside man or the CLI tool and attach accordingly.
    b. If project is targeting full framework and the break point is in the inside man code, the process name is dotnet-aspnet-codegenerator-design.exe
  6. The break point should hit.

Some common issues when debugging doesn’t hit the breakpoint:

  • The dotnet.exe process to which we attach isn’t correct

    • This typically happens if some other dotnet command is launched after scaffolding was launched (running scaffolding commandline first and then opening scaffolding solution will always cause the topmost dotnet process to be one launched by VS.)

  • The version of package in the project isn’t correct.

    • You can check this by inspecting the project.assets.json of the project and comparing it with the latest package created in the artifacts folder.

All 7 comments

@ali-raza-iftikhar, the below steps are what I use for debugging.
Let me know if you hit any issues with this.

Steps for debugging

  1. Add the above line of code in a place that is before where you want the first breakpoint.
while (!System.Diagnostics.Debugger.IsAttached){ }
  1. Build the packages (run ā€˜build /t:compile’ on the repo)
  2. Create a new web project (or use an existing one).
    a. Add a new NuGet.config file to point to the artifacts\build folder under the repo directory.
    b. Update the version numbers for the scaffolding packages in the project to pick up latest.
  3. Open Scaffolding solution in VS (another instance if project is open in VS) and add a break point.
  4. Scaffold from VS or command line.
  5. From scaffolding solution, attach debugger to dotnet.exe (there maybe multiple, but ususally this is the one on top of the list).
    a. Need to figure out if the code is in inside man or the CLI tool and attach accordingly.
    b. If project is targeting full framework and the break point is in the inside man code, the process name is dotnet-aspnet-codegenerator-design.exe
  6. The break point should hit.

Some common issues when debugging doesn’t hit the breakpoint:

  • The dotnet.exe process to which we attach isn’t correct

    • This typically happens if some other dotnet command is launched after scaffolding was launched (running scaffolding commandline first and then opening scaffolding solution will always cause the topmost dotnet process to be one launched by VS.)

  • The version of package in the project isn’t correct.

    • You can check this by inspecting the project.assets.json of the project and comparing it with the latest package created in the artifacts folder.

I will try. but thanks in advance for writing detailed explanation. will let you know if any issue occurred.

Brother it worked. Today tested it. Lot of thanks. You have helped me from scratch of understanding and writing scaffolding till debugging. It all worked :-) your help is appreciated. šŸ‘

I have just one issue. Which i don't think belongs to you/scaffolding. But hopefully you can help me for that. I am trying to create scaffolding package from VS2017 pack. I want template folder to be included as well. How i can achieve that?
Even if you can't help me for this, i am still thankful to you for your help. :-)

I want template folder to be included as well. How i can achieve that?

You would need to specify the files to be included as part of the package in the csproj file.
Take a look at https://github.com/aspnet/Scaffolding/blob/dev/src/Microsoft.VisualStudio.Web.CodeGenerators.Mvc/Microsoft.VisualStudio.Web.CodeGenerators.Mvc.csproj#L13-L15

Awesome thanks brother šŸ‘

Closing this.

Was this page helpful?
0 / 5 - 0 ratings