将自定义信息添加到 CSPROJ 文件
作为我们开发生命周期的一部分,我们在项目中针对 C# 源代码运行了许多流程。
这些进程由 GUI 驱动,该 GUI 当前读取 *.csproj 文件以查找项目中使用的源文件。这很好用。
我们现在有一个新要求,即提供一些需要调用 Web 服务的验证过程。需要向 Web 服务提供一些特定于项目的凭据。理想情况下,我们可以在 *.csproj 文件中输入并存储这些凭据,但我没有看到扩展它的方法 - 有吗?
我们真的不想引入新的配置。如果我们可以帮助的话,只为这些设置创建文件。是否可以像 *.csproj 文件一样存储信息,如果没有,是否有其他地方可以放置它。
谢谢
As part of our development life cycle we have a number of process that we run against the C# source in our projects.
The processes are driven off a GUI that currently reads the *.csproj file to find the source files used within the project. This works fine.
We now have a new requirement to provide some validation processes that require a call out to a web-service. The web-service needs to be provided with some credentials that are project specific. Ideally we could enter and store these credentials within the *.csproj file but I don't see a means of extending it - is there?
We don't really want to introduce a new config. file just for these settings if we can help it. Is it possible to store information like this is the *.csproj file, if not is there any other place to put it.
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
.csproj
文件基本上是一个 MSBuild 文件,因此您可以使用自定义值扩展它。如果右键单击 Visual Studio 中的项目并选择“卸载项目”,该项目将“灰显”,然后您可以再次右键单击并选择编辑 [ProjectFileName].csproj
。然后,您可以添加类似于以下内容的内容:当修改项目(即添加/删除文件)时,此应该被保留,并且您可以使用您选择的方法从文件中检索值。
The
.csproj
file is basically an MSBuild file, as such you can extend it with custom values. If you right-click on a project in Visual Studio and choose "Unload Project", the project will "grey out" and you can then right-click again and chooseEdit [ProjectFileName].csproj
. You can then add something similar to the following:This should be persisted when the project is modified (i.e. files added/removed) and you can retrieve the values from the file, using the method of your choice.
VS 项目支持“项目扩展”。这些是直接存储在 csproj/vbproj 文件中的自定义数据。您甚至可以从 VS 轻松读取和写入它们。例如,下面的 VS 宏写入这样的自定义设置:
下面将其读回:
csproj 文件中的代码如下所示:
当然,这是持久化的,不会被 VS 覆盖。
VS projects support "project extensions". These are custom data stored directly in csproj/vbproj files. You can very easily read and write them even from VS. For example, the following VS macro writes such custom setting:
The following reads it back:
And the code in csproj file looks like:
Of course, this is persisted and will not be overwritten by VS.
我知道您会忽略它,但最明显且可能推荐的位置是在 config 文件中。虽然加密了。
每个项目一个配置文件适用于大多数情况,而且恕我直言,这并不是很大的开销。
I know you dismiss it but the most obvious, and probably recommended, place is in the config file. Albeit encrypted.
One config file per project does for most cases and is not a large overhead imho.