繁体   English   中英

以编程方式获取与Visual Studio解决方案文件(* .sln)中的GUID相匹配的Assembly GUID

[英]Getting Assembly GUID programmatically that matches that in Visual studio solution file (*.sln)

我想获得在Visual Studio解决方案文件(* .sln)中使用的程序集GUID,如下所示:

Microsoft Visual Studio Solution File, Format Version 12.00
 #Visual Studio 2010

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibrary3", "..\ClassLibrary3\ClassLibrary3.csproj", "{5B402A1B-18B1-4D88-804A-BC0E58EF3730}"
EndProject

我尝试了下面的代码,都失败了

  //attempt 1: 
var assembly = Assembly.LoadFile(grandProject.AssemblyFilePath);
var id = assembly.GetType().GUID.ToString();

    //attempt 2
var attribute = (GuidAttribute)assembly.GetCustomAttributes(typeof(GuidAttribute), true)[0];
var id = attribute.Value;

任何想法?

* .sln文件中使用的汇编guid位于* .csproj文件中

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>

    <ProjectGuid>{5B402A1B-18B1-4D88-804A-BC0E58EF3730}</ProjectGuid>

  </PropertyGroup>
</Project>

暂无
暂无

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

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