This post is part of a series of blog posts about bad codes or bad practices I’ve come across. Note that this is my personal opinion and some of the things I mention could be debatable.
Post 1: Code review, why it matters
Post 2: Not including JS, CSS and static content files in project
Post 3: Let’s just not unit test our code
Post 4: Don’t pass dependencies into helper methods
Post 5: Inline SQL query statement in static helper class
A few months ago, I get assigned to work on a project that has been going on for a while. First thing I notice that none of the JS files, CSS or static content files are included in the project (the files are in the project folder in file system but not in Visual Studio). I ask why they aren’t included and the response is, and I quote:
Well, technically MSBuild doesn’t care about them as it doesn’t use them. Gulp is instructed to iterate through the file system to grab all the interesting files it can compile. So it doesn’t matter if the csproj has the files included or not, the build pipeline will continue to work. Why add it if it is not part of the C# project?
Firstly, sure, the build doesn’t need these files included to build but if this is the argument then why would you include the views. The views are not required to build, might as well exclude them too. In fact, MSBuild does care about them as they are marked as “Content”, not none. In .Net Core, the project file will include the entire folders, if you want to specify these files as excluded you would have to do it manually. The project file csproj to xproj to make it clearer that it isn’t just cs files in solutions.
Secondly, these files are definitely part of the project because they are referenced in the code. In my opinion I just don’t see any valid reason for not including these files in the project, unless they are auto generated. If they are part of the project, they should be included. That way you get Intellisense and avoid Visual Studio accidentally removing them from source control. Not including these files might make new developers in the team think that these are no longer needed and delete them. Also as I have suspected, this same person eventually have problem with git not including some of the JS files in his commit and broken CSS styling. He later gets all these working again after including them in the project.
At the time I join the team, the team has been thinking about extracting all the JS files (the team uses React for front end) into its own project. I ask if the team is moving the JS files into its own React project, would they include them in the new project or just let Gulp to figure it out itself and have a blank project? Their answer is that the files should be included. This is contradicting the above argument because it is no different to the existing set up. The new project, similarly to the existing project, would not need to include these files to build.
In conclusion, any JS, CSS and static content files should be included in the project. This allows Intellisense to work better and avoids Visual Studio accidentally removing them from source control. There is no valid argument for not including these in the project. This kind of argument should not have been had in the first place.
David
good post