2

I'm trying to port my C# Windows Form project from .csproj to CSharp CMake CMakeLists.txt. I successfully made CMakeLists.txt similar to here. The only problem is when the project opened with CMakeLists.txt, the Form Designer is not available (as shown below). Is it any way to fix the problem?

csproj:

enter image description here

CMakeLists.txt:

enter image description here

Kevin
  • 16,549
  • 8
  • 60
  • 74
ma.mehralian
  • 1,274
  • 2
  • 13
  • 29

1 Answers1

2

Your second image (from your CMake-generated project) is in a different View than the first image. The first image is the Solution View, in which the Form1.cs and Form1.Designer.cs files are grouped to show that the Form Designer is available. The CMake (second) image is showing the Folder View, which does not group the two files together.

CMake does not control what view you see in Visual Studio, your Visual Studio IDE controls this. The toolbar across the top of Solution Explorer has a button (called "Switch Views") to switch from a solution view to a folder view (and vice versa). You can use this to switch your perspective back to Solution View so the Form Designer is shown.


Note: This button has a bug in Visual Studio 2019 (see here), so switching back to Solution View may not work as expected. I've worked around this issue by simply closing and re-opening the Solution.

When you open the solution file (via File > Open > Project/Solution...), your default View should be the Solution View, and the Form Designers for your forms sources should be accessible. If you open the solution by doing File > Open > CMake..., your default View will be Folder View, which is not what you want.

Kevin
  • 16,549
  • 8
  • 60
  • 74
  • The **Switch Views** button has 2 options 1- **WindowsFormsApp** (seems folder view) similar to the image I posted 2- **CMake Targets View**. But non of them show Form Designer. (ps: here is a disabled option which shows **No Solutions Found** !? since the CMake generation finished successfully) – ma.mehralian Oct 24 '19 at 12:25
  • There will be no **Form Designer** view, only the **Folder View** and **Solution View**. The Form Designer for each source file is only accessible from the **Solution View**. It sounds like your VS2019 version is having the same bug I was experiencing. Try closing then re-opening the solution, the default view upon re-opening should be the **Solution View**. I expanded my answer to include this. – Kevin Oct 24 '19 at 12:32
  • Nothing happen! This is what I do: 1-File > Close Folder. 2- File > Open > CMake. Even I restart VS! [This](https://i.stack.imgur.com/Zc813.png) is my **Switch Views** – ma.mehralian Oct 24 '19 at 12:46
  • 1
    When you do **Open > CMake**, VS2019 will default to **Folder View**. You should open the native Visual Studio project or solution files though (`.sln`). Do **Open > Project/Solution...** and choose your *solution* file (`.sln`) to open in **Solution View**. I expanded my answer again to explain this. – Kevin Oct 24 '19 at 12:53
  • So after each time CMakeLists.txt changed, I should generate `.sln` again and then open in VS!? – ma.mehralian Oct 24 '19 at 13:12
  • 1
    You can modify your CMake files *within* VS2019. When building your project in VS2019 (**Build > Build Solution**), it will first check if your CMake files were changed. If so, it will re-run CMake for you, you don't have to do this manually. It will then prompt you to *reload* your solution, if the solution has changed; there is no need to close/re-open it manually either. After the solution reloads, your View should be *preserved* so it will still be in **Solution View**. – Kevin Oct 24 '19 at 13:18