在Visual Studio中在编译时获取程序集名称 [英] Get Assembly name at compile time in Visual Studio

查看:190
本文介绍了在Visual Studio中在编译时获取程序集名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以在Visual Studio中在设计时(即不使用反射或运行时API,例如System.Reflection.Assembly.GetEntryAssembly)来查找程序集名称?

Is there a way to find out the assembly name at design-time (i.e. not using reflection or runtime APIs such as System.Reflection.Assembly.GetEntryAssembly) from within Visual Studio?

该方案需要一个工具来获取Visual Studio项目最终将编译到的程序集名称.

The scenario requires a tool to get the assembly name that a Visual Studio project will eventually compile into.

这就像解析.csproj的AssemblyName属性一样-我想知道是否有任何API可以可靠地提供此信息.

This is like parsing the AssemblyName property of the .csproj - I am wondering if there are any APIs that can give this information reliably.

请不要用使用反射的运行时API进行回复-我需要程序集名称时没有程序集文件-csproj文件中只是程序集的元数据.

Please do not respond back with runtime APIs that use reflection - there is no assembly file present at the time I need the assembly name - just the metadata of the assembly in the csproj file.

推荐答案

在所有.csproj文件都是xml之后,您可以使用的"API"是LINQ to XML. (如果需要,您可以从解决方案文件中获取.csproj文件的位置,由于某种原因,该文件不是XML,但很容易解析)

The "API" you could use is LINQ to XML after all the .csproj file is just xml. (and you can get the location of the .csproj file if you need from the solution file which for some reason is not XML but can be easily parsed)

这篇关于在Visual Studio中在编译时获取程序集名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆