Historically format of .csproj file has been complex and the developers dread to edit it. The new format is much simpler to edit.
When you want to edit a .csproj file that has the old format, you need to unload the project, edit the project and reload it. As a result, the developer loses the context of his project files and work. Also, the imported packages are stored in two places 1) package.config and 2) .csproj file. So, if you are editing one, you want to make sure that the other file stays in sync.
The new file format provides solutions to these problems. It provides the following advantages:
1. Easier to edit (fat-free) format
The new format is much less cluttered than the classic one. So it is easier to edit and maintain.
2. Simultaneously edit and view
As I mentioned earlier, one can simply right click on the project file and click edit. You need not unload, edit and reload the project. It saves a lot of time and pain.
3. Single package reference
Traditionally, the imported packages are stored in the packages.config file and references to the platform specific library is stored in the project file. Should you need to manually edit somethings, having references in two places is not easy to maintain. The new format has PackageReference in one place.
4. AssemblyInfo in the project
AssemblyInfo is another file that can become redundant. With the new format, contents of the file can be stored in the project file itself.
- For the Library project that does not have any NuGet package reference
- Right Click and Unload the project
- Right click and Edit the project file.
- Replace the top two lines
With this line.
- Add the following group with appropriate framework
- Remove all the property groups that reference configuration
- Retain all the groups that refer to reference
- Remove all item groups that refer to code files. Do not worry, they will be picked up from the folder.
- Remove all the item groups that import targets
- With this, the project should be ready in the new format.
- Open the project and delete the assemblyinfo.cs file.
- Now you can view and edit the project at the same time
- The Unit Test and REST Api projects require conversion of packages to PackageReference
- There are several NuGet Package Reference upgrader extensions available. Install the one that you prefer.
- Right click on the packages.config file in the project and choose upgrade/Migrate to PackageReference. This should delete the packages.config file and add appropriate references in the .csproj file
- Follow the same steps as in Step 1.
- In the ProjectReference entry, you can remove the elements for the project guid and name. The relative path would be sufficient.
- More for ASP.NET project
- Remove ProjectExtenstions element from the .csproj file
- Keep all the content elements
- Go to Properties->Debug tab and edit the following settings
- Executable as iisexpress
- Application arguments as
- This will add lauchSettings..json to properties folder
Here is the GitHub Repo:
Let me know, if you have any questions. Please share it with fellow developers to make their life easier.