简体   繁体   English

如何编辑.csproj文件

[英]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".当我使用 .NET Framework 4.0 MSBUILD.EXE 文件编译 my.csproj 文件时,出现错误:在“website01.csproj”的当前上下文中找不到“lable01”。

Actually, I need to add every ASP.NET page with its code-behind file's reference.实际上,我需要添加每个 ASP.NET 页面及其代码隐藏文件的引用。 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.我希望这意味着我需要在那个 .csproj 文件中添加表单名称“LABLE01”,但我不知道语法。 Anybody please do provide me with the syntax to add form name in.csproj file.请任何人给我提供在 .csproj 文件中添加表单名称的语法。

The CSPROJ file, saved in XML format, stores all the references for your project including your compilation options. CSPROJ文件以 XML 格式保存,存储项目的所有引用,包括编译选项。 There is also an SLN file, which stores information about projects that make up your solution.还有一个 SLN 文件,用于存储有关构成您的解决方案的项目的信息。

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:如果您使用的是 Visual Studio 并且需要查看或编辑您的CSPROJ文件,则在 Visual Studio 中,您可以按照以下简单步骤进行操作:

  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".右键单击项目(在解决方案资源管理器中标记为不可用),然后单击“编辑 yourproj.csproj”。 This will open up your CSPROJ file for editing.这将打开您的 CSPROJ 文件进行编辑。
  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".您可以右键单击项目文件,选择“卸载项目”,然后您可以通过选择“编辑项目名称.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.请参阅如何:卸载和重新加载MSDN 上的项目


Since project files are XML files, you can also simply edit them using any text editor that supports Unicode (notepad, notepad++ etc...)由于项目文件是 XML 文件,您还可以使用任何支持 Unicode 的文本编辑器(记事本、记事本++等...)

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.由于问题没有直接提到 Visual Studio,我将在 JetBrains Rider 中发布如何执行此操作。

From context menu从上下文菜单

  1. Right-click your project右键单击您的项目
  2. Go to edit去编辑
  3. Edit '{project-name.csproj}'编辑“{project-name.csproj}”

在此处输入图片说明

With shortcut有快捷方式

  1. Select project选择项目
  2. Press F4F4

There is an easier way so you don't have to unload the project.有一种更简单的方法,因此您不必卸载项目。 Just install this tool called EditProj in Visual Studio:只需在 Visual Studio 中安装这个名为EditProj 的工具:
https://marketplace.visualstudio.com/items?itemName=EdMunoz.EditProj 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"在 vs 2019 版本 16.8.2 中右键单击您的项目名称,然后单击“编辑项目文件” 在此处输入图片说明

For JetBrains Rider:对于 JetBrains Rider:

First Option第一个选项

  1. Unload Project卸载项目
  2. Double click the unloaded project双击卸载的项目

Second option:第二种选择:

  1. Click on the project点击项目
  2. Press F4按F4

That's it!就是这样!

Sorry, most efficient way with out stuffing your proj file is.抱歉,最有效的方法是填充您的 proj 文件。

  1. right click the file.右键单击该文件。
  2. goto properties转到属性
  3. where Build Action option is set it to NONE.其中 Build Action 选项将其设置为 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.对我来说,这个练习不到 10 秒。 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.手动尝试将 compile... 行输入 csproj 不仅会使您的项目无法使用,而且也不可能在大规模应用程序上维护。 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.从上下文菜单中选择Open 在此处输入图片说明

That is it!这就对了!

You will see the *.csproj file opened inside Visual Studio Editor.您将看到在 Visual Studio 编辑器中打开的*.csproj文件。
After you can switch back to a Solution/Project view (see step 1).在您可以切换回解决方案/项目视图之后(参见步骤 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.从 Visual Studio 2019 (v. 16) 开始,您可以通过双击项目来编辑*.csproj文件,只需确保您从设置中打开了该选项。

在此处输入图片说明

To open the.csproj file:要打开 .csproj 文件:

  • open the solution explorer 1打开解决方案资源管理器1
  • Click on the Edit Project File option 2单击“编辑项目文件”选项2

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

For Visual Studio-version: 8.1.5,对于 Visual Studio 版本: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在 rider 中,您可以启用“单击打开项目文件”只需 go 到solution options menu ,然后单击单击open project files with single click

在此处输入图像描述

You can also open the.csproj by double-clicking on the project file.您也可以通过双击项目文件打开.csproj。 So no need to right click and select edit project file.因此无需右键单击和 select 编辑项目文件。 Just double click and that is it.只需双击即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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