KreativJos / csharpextensions

C# Extensions for Visual Studio Code
MIT License
73 stars 35 forks source link

[Add] BuildActions #41

Open KreativJos opened 3 years ago

KreativJos commented 3 years ago

Reworked parts of PR #17 from hampoelz:

hampoelz commented 3 years ago

First of all, thank you for the revision of my PR @KreativJos.

I think it would be important to add default BuildActions for files like in VS:

  1. It is very annoying to manually select BuildActions every time you want to add predefined files. (I don't see any reason why they shouldn't get a BuildAction entry in the project file by default - you want to add them to your project, don't you?)
  2. When adding UWP Pages / Windows it's problematic if you select "You don't want to select the BuildAction for each file individually". (Your .cs and .cs.xaml files will get the same BuildAction)
  3. If you add UWP Pages / Windows and first set the BuildAction on the .cs file instead of the .cs.xaml file, your .cs file will not be linked to the .xaml page.
  4. You need to know all of the BuildActions for multiple file types.

Since I'm now working on a C# project again, I will test this PR for the next few weeks.

KreativJos commented 2 years ago

Will try to take a look at this tomorrow or Wednesday

KreativJos commented 2 years ago

@hampoelz Rewrote most of the writer & surrounding stuff. Now it is using interface types to ensure correct handling (learned a lot about typescript this way).

First of all, thank you for the revision of my PR @KreativJos.

I think it would be important to add default BuildActions for files like in VS:

  1. It is very annoying to manually select BuildActions every time you want to add predefined files. (I don't see any reason why they shouldn't get a BuildAction entry in the project file by default - you want to add them to your project, don't you?)
  2. When adding UWP Pages / Windows it's problematic if you select "You don't want to select the BuildAction for each file individually". (Your .cs and .cs.xaml files will get the same BuildAction)
  3. If you add UWP Pages / Windows and first set the BuildAction on the .cs file instead of the .cs.xaml file, your .cs file will not be linked to the .xaml page.
  4. You need to know all of the BuildActions for multiple file types.

Since I'm now working on a C# project again, I will test this PR for the next few weeks.

As for your points:

  1. Since .net core 1, project files do not require inclusion of compilation files. They are included by reference when used in other files. One could see benefit in keeping their csproj-files clean by simply not including .cs-files. I can see why you would want them though - I'll create a setting for this (possibly with default build action)
  2. That indeed is an issue with the current approach. I propose to assume the action for the page (xaml / cshtml / etc) if both are added, because that one should be obvious. Assuming build action might even be a nice approach for every file?
  3. Correct, but should be solved by linking in the proposal above
  4. I do not know what issue you are referring to here - creating a map for known build actions for file extensions?
hampoelz commented 2 years ago

Thank you for your work @KreativJos! I'll test the changes soon.

  1. Since .net core 1, project files do not require inclusion of compilation files. They are included by reference when used in other files. One could see benefit in keeping their csproj-files clean by simply not including .cs-files. I can see why you would want them though - I'll create a setting for this (possibly with default build action)

That's interesting, I didn't know that. However, adding a setting is a good approach and ensures backwards compatibility.

  1. That indeed is an issue with the current approach. I propose to assume the action for the page (xaml / cshtml / etc) if both are added, because that one should be obvious. Assuming build action might even be a nice approach for every file?
  2. Correct, but should be solved by linking in the proposal above
  3. I do not know what issue you are referring to here - creating a map for known build actions for file extensions?

Yeah you're totally right. - One solution I had in mind was to map the build action based on the file extension (as you already wrote in 4.) to automatically add the files Build Actions - if the setting is active (as in 1. discussed). This would also eliminate the need to remember BuildActions for file types. (Refs to 4.) When adding a xaml/cshtml/etc file, it should be checked if there is a cs file with the same name and with the build action "compile" in the folder so that these two files can be linked.