如何以编程方式获取我的应用程序构建的Visual Studio版本?

时间:2022-06-05 07:01:44

How can I programmatically (C#) obtain the version of Visual Studio my application was built with?

我如何以编程方式(C#)获取我的应用程序构建的Visual Studio版本?

5 个解决方案

#1


Looking at the compiled assembly there is no way you can differentiate between one built with a command line csc or built with visual studio.

查看已编译的程序集,您无法区分使用命令行csc构建的程序集或使用visual studio构建的程序集。

#2


You could add a new appSettings key in your web.config, and then manually update the value as developers take over in the future.

您可以在web.config中添加新的appSettings键,然后在开发人员将来接管时手动更新该值。

The .csproj file contains meta data that you could query from.

.csproj文件包含您可以查询的元数据。

#3


System.Environment.Version gives you the .NET version you are using...I know it's not what you asked for, but something interesting.

System.Environment.Version为您提供了您正在使用的.NET版本...我知道它不是您要求的,而是一些有趣的东西。

#4


You can build your application with other tools such as MSBuild. In some larger working environments the F5 build and run is disabled and have much more complext build systems.

您可以使用其他工具(如MSBuild)构建应用程序。在一些较大的工作环境中,F5构建和运行被禁用,并且具有更多的Complext构建系统。

I don't think it is possible to tell which version other than the .net version which is requiured.

我认为不可能分辨出除了.net版本之外的哪个版本。

#5


I can categorically tell you that for a standard assembly, this is not possible. There is nothing that visual studio embeds in any of the metadata that gives you this information. So unfortunately this is not possible - the best you can do is make an educated guess (e.g. if it targets .NET framework 4.0 then it's probably Visual Studio 10). However, it's not just Visual Studio that can build managed code.

我可以断然告诉你,对于标准装配,这是不可能的。视觉工作室没有任何内容嵌入到为您提供此信息的任何元数据中。所以不幸的是,这是不可能的 - 你能做的最好就是做出有根据的猜测(例如,如果它针对的是.NET framework 4.0,那么它可能就是Visual Studio 10)。但是,不只是Visual Studio可以构建托管代码。

What's the reason behind this? If we understand the core task there may be alternatives.

这背后的原因是什么?如果我们理解核心任务,可能会有其他选择。

#1


Looking at the compiled assembly there is no way you can differentiate between one built with a command line csc or built with visual studio.

查看已编译的程序集,您无法区分使用命令行csc构建的程序集或使用visual studio构建的程序集。

#2


You could add a new appSettings key in your web.config, and then manually update the value as developers take over in the future.

您可以在web.config中添加新的appSettings键,然后在开发人员将来接管时手动更新该值。

The .csproj file contains meta data that you could query from.

.csproj文件包含您可以查询的元数据。

#3


System.Environment.Version gives you the .NET version you are using...I know it's not what you asked for, but something interesting.

System.Environment.Version为您提供了您正在使用的.NET版本...我知道它不是您要求的,而是一些有趣的东西。

#4


You can build your application with other tools such as MSBuild. In some larger working environments the F5 build and run is disabled and have much more complext build systems.

您可以使用其他工具(如MSBuild)构建应用程序。在一些较大的工作环境中,F5构建和运行被禁用,并且具有更多的Complext构建系统。

I don't think it is possible to tell which version other than the .net version which is requiured.

我认为不可能分辨出除了.net版本之外的哪个版本。

#5


I can categorically tell you that for a standard assembly, this is not possible. There is nothing that visual studio embeds in any of the metadata that gives you this information. So unfortunately this is not possible - the best you can do is make an educated guess (e.g. if it targets .NET framework 4.0 then it's probably Visual Studio 10). However, it's not just Visual Studio that can build managed code.

我可以断然告诉你,对于标准装配,这是不可能的。视觉工作室没有任何内容嵌入到为您提供此信息的任何元数据中。所以不幸的是,这是不可能的 - 你能做的最好就是做出有根据的猜测(例如,如果它针对的是.NET framework 4.0,那么它可能就是Visual Studio 10)。但是,不只是Visual Studio可以构建托管代码。

What's the reason behind this? If we understand the core task there may be alternatives.

这背后的原因是什么?如果我们理解核心任务,可能会有其他选择。