简体   繁体   中英

How to edit .csproj file

When I am compiling my.csproj file using .NET Framework 4.0 MSBUILD.EXE file, I am getting an error: "lable01" not found in the current context of "website01.csproj".

Actually, I need to add every ASP.NET page with its code-behind file's reference. I've done it, it's working fine, but the above error is pending.

I hope it means that I need to add form name "LABLE01" in that.csproj file, but I do not know the syntax. Anybody please do provide me with the syntax to add form name in.csproj file.

The CSPROJ file, saved in XML format, stores all the references for your project including your compilation options. There is also an SLN file, which stores information about projects that make up your solution.

If you are using Visual Studio and you have the need to view or edit your CSPROJ file, while in Visual Studio, you can do so by following these simple steps:

  1. Right-click on your project in solution explorer and select Unload Project
  2. Right-click on the project (tagged as unavailable in solution explorer) and click "Edit yourproj.csproj". This will open up your CSPROJ file for editing.
  3. After making the changes you want, save, and close the file. Right-click again on the node and choose Reload Project when done.

You can right click the project file, select "Unload project" then you can open the file directly for editing by selecting "Edit project name.csproj".

You will have to load the project back after you have saved your changes in order for it to compile.

See How to: Unload and Reload Projects on MSDN.


Since project files are XML files, you can also simply edit them using any text editor that supports Unicode (notepad, notepad++ etc...)

However , I would be very reluctant to edit these files by hand - use the Solution explorer for this if at all possible. If you have errors and you know how to fix them manually, go ahead, but be aware that you can completely ruin the project file if you don't know exactly what you are doing.

Since the question is not directly mentioning Visual Studio, I will post how to do this in JetBrains Rider.

From context menu

  1. Right-click your project
  2. Go to edit
  3. Edit '{project-name.csproj}'

在此处输入图片说明

With shortcut

  1. Select project
  2. Press F4

There is an easier way so you don't have to unload the project. Just install this tool called EditProj in Visual Studio:
https://marketplace.visualstudio.com/items?itemName=EdMunoz.EditProj

Then right click edit you will have a new menu item Edit Project File :)
在此处输入图片说明

in vs 2019 Version 16.8.2 right click on you project name and click on "Edit Project File" 在此处输入图片说明

For JetBrains Rider:

First Option

  1. Unload Project
  2. Double click the unloaded project

Second option:

  1. Click on the project
  2. Press F4

That's it!

Sorry, most efficient way with out stuffing your proj file is.

  1. right click the file.
  2. goto properties
  3. where Build Action option is set it to NONE.
  4. Do a build (yes you may get build error if you do even better)
  5. go back to properties of that file
  6. set Build Action option is set it back to Compile.
  7. rebuild.

  8. Congratulate your self for being smarter than everyone else and not ****ing you project. For me this exercise took under 10 seconds. Where as manually trying to input the compile... line into the csproj not only can render your project unusable but it is also impossible to maintain on large scale application. Better to keep source version control software to do the updates. If you need to cross merge branches then doing the above is amazing :).

Here is my option to Edit the project file without the need to Unload the project:

  1. Open Solution Explorer and switch to folder view: 在此处输入图片说明

  2. Navigate to the Project which you want to edit inside the Solution folders and right-click on it.

  3. Choose Open from the Context Menu. 在此处输入图片说明

That is it!

You will see the *.csproj file opened inside Visual Studio Editor.
After you can switch back to a Solution/Project view (see step 1).

在此处输入图片说明


Update:

Starting from the Visual Studio 2019 (v. 16) you can edit the *.csproj file by double-clicking on the Project, just make sure that you have the option turned On from the settings.

在此处输入图片说明

To open the.csproj file:

  • open the solution explorer 1
  • Click on the Edit Project File option 2

它是一个内置选项 .Net core 和 .Net 标准项目

For Visual Studio-version: 8.1.5,

  1. Right click on the project folder.
  2. Click "Tools", then "Edit File".

A little late to the conversation but I found a better option. In rider you can enable "open project files with single click" Just go to the solution options menu and then click in open project files with single click

在此处输入图像描述

You can also open the.csproj by double-clicking on the project file. So no need to right click and select edit project file. Just double click and that is it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM