Skip to content

Commit

Permalink
Merge pull request #24 from gavardev/fix_project_with_duplicated_sect…
Browse files Browse the repository at this point in the history
…ions

Fixes problem with projects containing duplicated sections
  • Loading branch information
ChrisMaddock authored Jul 21, 2018
2 parents 7fe84e9 + 87bed33 commit 0f60d06
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/extension/VSProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ private void LoadMSBuildProject()
else
assemblyName = assemblyName + ".dll";

string commonOutputPath = null;
string commonOutputPath = null;
var explicitOutputPaths = new Dictionary<string, string>();

foreach (XmlElement configNode in nodes)
{
Expand All @@ -377,12 +378,15 @@ private void LoadMSBuildProject()
commonOutputPath = outputPath;
continue;
}

if (outputPathElement != null)
explicitOutputPaths[name] = outputPath;

if (outputPath == null)
outputPath = commonOutputPath;
outputPath = explicitOutputPaths.ContainsKey(name) ? explicitOutputPaths[name] : commonOutputPath;

if (outputPath != null)
_configs.Add(name, new ProjectConfig(this, name, outputPath.Replace("$(Configuration)", name), assemblyName));
_configs[name] = new ProjectConfig(this, name, outputPath.Replace("$(Configuration)", name), assemblyName);

}
}
Expand Down
22 changes: 22 additions & 0 deletions src/tests/VisualStudioProjectLoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,28 @@ public void FromProjectWithTemplatedPaths()
"Invalid FixedPath assembly path");
}
}

[Test]
public void ProjectWithDuplicatedSections()
{
using (var file = new TestResource("test-duplicated-key-project.csproj", NormalizePath(@"csharp-sample\csharp-sample.csproj")))
{
IProject project = _loader.LoadFrom(file.Path);
Assert.AreEqual(3, project.ConfigNames.Count);

var debugPackage = project.GetTestPackage("Debug");
Assert.AreEqual(1, debugPackage.SubPackages.Count, "Debug should have 1 assembly");

var releasePackage = project.GetTestPackage("Release");
Assert.AreEqual(1, releasePackage.SubPackages.Count, "Release should have 1 assembly");

var secondDebugPackage = project.GetTestPackage("Debug2ndTest");
Assert.AreEqual(1, secondDebugPackage.SubPackages.Count, "Debug2ndTest should have 1 assembly");
Assert.AreEqual(1, secondDebugPackage.SubPackages.Count, "Debug2ndTest should have 1 assemblies");
Assert.That(secondDebugPackage.SubPackages[0].FullName, Does.EndWith(NormalizePath(@"\csharp-sample\Debug2ndTest\SecondTest\Test.exe")),
"Invalid Debug2ndTest assembly path");
}
}

private string NormalizePath(string path)
{
Expand Down
83 changes: 83 additions & 0 deletions src/tests/resources/test-duplicated-key-project.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<RootNamespace>Test</RootNamespace>
<AssemblyName>Test</AssemblyName>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A518F172-99B1-4A83-8A40-D9EFBA0E4270}</ProjectGuid>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<StartAction>Project</StartAction>
<NoWin32Manifest>False</NoWin32Manifest>
<BaseIntermediateOutputPath>.obj\Test</BaseIntermediateOutputPath>
<IntermediateOutputPath>.obj\Test\$(Configuration) - $(Platform)\</IntermediateOutputPath>
<OutputPath>.bin\$(Configuration)\Test\</OutputPath>
<ApplicationManifest>app.manifest</ApplicationManifest>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<Optimize>False</Optimize>
<DebugSymbols>true</DebugSymbols>
<DebugType>Full</DebugType>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<Optimize>True</Optimize>
<DebugSymbols>false</DebugSymbols>
<DebugType>None</DebugType>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<BaseAddress>4194304</BaseAddress>
<PlatformTarget>AnyCPU</PlatformTarget>
<FileAlignment>4096</FileAlignment>
<Prefer32Bit>False</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Xml" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<PostBuildEvent>rem some post-build actions</PostBuildEvent>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<PostBuildEvent>rem some post-build actions</PostBuildEvent>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'x86' ">
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<BaseAddress>4194304</BaseAddress>
<PlatformTarget>x86</PlatformTarget>
<FileAlignment>4096</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug' ">
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release' ">
<DefineConstants>TRACE;RELEASE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug2ndTest' ">
<OutputPath>$(Configuration)\SecondTest\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug2ndTest' ">
<Optimize>False</Optimize>
<DebugSymbols>true</DebugSymbols>
<DebugType>Full</DebugType>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
</PropertyGroup>
</Project>
3 changes: 3 additions & 0 deletions src/tests/vs-project-loader.tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@
<ItemGroup>
<EmbeddedResource Include="resources\TestTemplatedPaths.csproj" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="resources\test-duplicated-key-project.csproj" />
</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.
Expand Down

0 comments on commit 0f60d06

Please sign in to comment.