.csprojファイルの設定を変更するプログラムでは、次のlinq to xmlステートメントは、常に「オブジェクトがオブジェクトのインスタンスに設定されていません」を返します。
static void Main(string[] args)
{
string rootDir =
@"e:\path\to\proj\file\foo.csproj";
var xDoc = XDocument.Load(rootDir);
var ns = xDoc.Root.Name.Namespace;
var hasConditions = xDoc.Root.Elements(ns + "PropertyGroup")
.Where(x => x.Attribute("Condition") != null);
Console.WriteLine(hasConditions.Count());
try
{
var debugConfig = xDoc.Root.Elements(ns + "PropertyGroup")
.Where(x => x.Attribute("Condition")
.Value == " '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ");
Console.WriteLine(debugConfig.Count());
}
catch
{
Console.WriteLine("doesn't work");
}
}
完全なプロジェクトファイル:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{F08E2AEB-A1C2-43F9-A93C-38AF2A99C96A}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CommunicationSystem.XmlLoading.Common</RootNamespace>
<AssemblyName>CommunicationSystem.XmlLoading.Common</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<RunCodeAnalysis>true</RunCodeAnalysis>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<RunCodeAnalysis>true</RunCodeAnalysis>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'DEV|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\DEV\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'SIT|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\SIT\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'QA|AnyCPU'">
<OutputPath>bin\QA\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="StorageSystem">
<HintPath>..\..\..\GlobalDependencies\StorageSystem\beta\StorageSystem.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Common\IEnumerableExtensions.cs" />
<Compile Include="Common\XmlLoaderBase.cs" />
<Compile Include="Configuration\SchemasConfigurationElement.cs" />
<Compile Include="Configuration\SettingsConfigurationElement.cs" />
<Compile Include="Configuration\TConfigurationElementCollection.cs" />
<Compile Include="Configuration\XmlLoadingConfigurationSection.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Validation\XValidationResult.cs" />
<Compile Include="Validation\XValidator.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
私の疑惑は、それが属性値の空白と関係があるということですが、私には確信が持てません....他の誰かが同様の何かに直面していますか?