我有读取proj
文件并检查其assembly
名称的代码。
XNamespace msbuild = "http://schemas.microsoft.com/developer/msbuild/2003";
XDocument projDefinition = XDocument.Load(projPath);
assemblyName = projDefinition
.Element(msbuild + "Project")
.Element(msbuild + "PropertyGroup")
.Element(msbuild + "AssemblyName")
.Value;
上面的代码在 99% 的时间里都能完美运行。今天它Null Object Reference Exception
试图assembly
从下面的代码中获取名称。顶部property group element
和import element
通常朝向proj
文件的底部。
我的问题是为什么XDocument
不过去Import Element
也不接其他propertygroup elements
?
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<UseGlobalApplicationHostFile />
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Some Elements ...
<AssemblyName>AssemblyNameGoesHere</AssemblyName>