Skip to content

Commit

Permalink
Read and determine default OutputPath for projects
Browse files Browse the repository at this point in the history
  • Loading branch information
FredrikGoransson committed Jan 30, 2018
1 parent 71d138c commit 3039e5e
Show file tree
Hide file tree
Showing 15 changed files with 426 additions and 8 deletions.
54 changes: 52 additions & 2 deletions src/FG.Utils.BuildTools.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ce.Labs.Samples.CPSProject"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test", "Test", "{71BF5472-C079-453E-99FE-2C9EAA66D9B0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SampleProjects", "SampleProjects", "{7CCAED35-86A2-4E74-8071-C9991A2C288E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CPSSpecifics", "CPSSpecifics", "{45820ABF-31FB-48DD-8BFF-694764BDB994}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ce.Labs.Samples.CPSProjectNoOutputPath", "testing\samples\Ce.Labs.Samples.CPSProjectNoOutputPath\Ce.Labs.Samples.CPSProjectNoOutputPath.csproj", "{EC91F9E6-CAF9-441C-A1DA-82E1734181F8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ce.Labs.Samples.CPSProjectNoOutputPathNoRuntime", "testing\samples\Ce.Labs.Samples.CPSProjectNoOutputPathNoRuntime\Ce.Labs.Samples.CPSProjectNoOutputPathNoRuntime.csproj", "{CAF8ED2F-D408-4202-B868-628A1C9FD71B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ce.Labs.Samples.CPSProjectNoOutputPathx64", "testing\samples\Ce.Labs.Samples.CPSProjectNoOutputPathx64\Ce.Labs.Samples.CPSProjectNoOutputPathx64.csproj", "{0CD13398-B5C6-43EB-8806-DA9F8E08977D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ce.Labs.Samples.CPSProjectNoOutputPathx64NoRuntime", "testing\samples\Ce.Labs.Samples.CPSProjectNoOutputPathx64NoRuntime\Ce.Labs.Samples.CPSProjectNoOutputPathx64NoRuntime.csproj", "{2426D84A-348B-4B4C-BE06-1A2CDDB6A3AA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -53,14 +65,52 @@ Global
{350B8A45-7F88-4243-96AE-6F591721117E}.Release|Any CPU.Build.0 = Release|Any CPU
{350B8A45-7F88-4243-96AE-6F591721117E}.Release|x64.ActiveCfg = Release|x64
{350B8A45-7F88-4243-96AE-6F591721117E}.Release|x64.Build.0 = Release|x64
{EC91F9E6-CAF9-441C-A1DA-82E1734181F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EC91F9E6-CAF9-441C-A1DA-82E1734181F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EC91F9E6-CAF9-441C-A1DA-82E1734181F8}.Debug|x64.ActiveCfg = Debug|Any CPU
{EC91F9E6-CAF9-441C-A1DA-82E1734181F8}.Debug|x64.Build.0 = Debug|Any CPU
{EC91F9E6-CAF9-441C-A1DA-82E1734181F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EC91F9E6-CAF9-441C-A1DA-82E1734181F8}.Release|Any CPU.Build.0 = Release|Any CPU
{EC91F9E6-CAF9-441C-A1DA-82E1734181F8}.Release|x64.ActiveCfg = Release|Any CPU
{EC91F9E6-CAF9-441C-A1DA-82E1734181F8}.Release|x64.Build.0 = Release|Any CPU
{CAF8ED2F-D408-4202-B868-628A1C9FD71B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CAF8ED2F-D408-4202-B868-628A1C9FD71B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CAF8ED2F-D408-4202-B868-628A1C9FD71B}.Debug|x64.ActiveCfg = Debug|x64
{CAF8ED2F-D408-4202-B868-628A1C9FD71B}.Debug|x64.Build.0 = Debug|x64
{CAF8ED2F-D408-4202-B868-628A1C9FD71B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CAF8ED2F-D408-4202-B868-628A1C9FD71B}.Release|Any CPU.Build.0 = Release|Any CPU
{CAF8ED2F-D408-4202-B868-628A1C9FD71B}.Release|x64.ActiveCfg = Release|x64
{CAF8ED2F-D408-4202-B868-628A1C9FD71B}.Release|x64.Build.0 = Release|x64
{0CD13398-B5C6-43EB-8806-DA9F8E08977D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0CD13398-B5C6-43EB-8806-DA9F8E08977D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0CD13398-B5C6-43EB-8806-DA9F8E08977D}.Debug|x64.ActiveCfg = Debug|x64
{0CD13398-B5C6-43EB-8806-DA9F8E08977D}.Debug|x64.Build.0 = Debug|x64
{0CD13398-B5C6-43EB-8806-DA9F8E08977D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0CD13398-B5C6-43EB-8806-DA9F8E08977D}.Release|Any CPU.Build.0 = Release|Any CPU
{0CD13398-B5C6-43EB-8806-DA9F8E08977D}.Release|x64.ActiveCfg = Release|x64
{0CD13398-B5C6-43EB-8806-DA9F8E08977D}.Release|x64.Build.0 = Release|x64
{2426D84A-348B-4B4C-BE06-1A2CDDB6A3AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2426D84A-348B-4B4C-BE06-1A2CDDB6A3AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2426D84A-348B-4B4C-BE06-1A2CDDB6A3AA}.Debug|x64.ActiveCfg = Debug|x64
{2426D84A-348B-4B4C-BE06-1A2CDDB6A3AA}.Debug|x64.Build.0 = Debug|x64
{2426D84A-348B-4B4C-BE06-1A2CDDB6A3AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2426D84A-348B-4B4C-BE06-1A2CDDB6A3AA}.Release|Any CPU.Build.0 = Release|Any CPU
{2426D84A-348B-4B4C-BE06-1A2CDDB6A3AA}.Release|x64.ActiveCfg = Release|x64
{2426D84A-348B-4B4C-BE06-1A2CDDB6A3AA}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{96869A2E-7D98-4BEB-AF94-21BD0A581970} = {71BF5472-C079-453E-99FE-2C9EAA66D9B0}
{8976B123-80BD-459A-BB2B-46DE19140EA2} = {71BF5472-C079-453E-99FE-2C9EAA66D9B0}
{350B8A45-7F88-4243-96AE-6F591721117E} = {71BF5472-C079-453E-99FE-2C9EAA66D9B0}
{8976B123-80BD-459A-BB2B-46DE19140EA2} = {7CCAED35-86A2-4E74-8071-C9991A2C288E}
{350B8A45-7F88-4243-96AE-6F591721117E} = {7CCAED35-86A2-4E74-8071-C9991A2C288E}
{7CCAED35-86A2-4E74-8071-C9991A2C288E} = {71BF5472-C079-453E-99FE-2C9EAA66D9B0}
{45820ABF-31FB-48DD-8BFF-694764BDB994} = {7CCAED35-86A2-4E74-8071-C9991A2C288E}
{EC91F9E6-CAF9-441C-A1DA-82E1734181F8} = {45820ABF-31FB-48DD-8BFF-694764BDB994}
{CAF8ED2F-D408-4202-B868-628A1C9FD71B} = {45820ABF-31FB-48DD-8BFF-694764BDB994}
{0CD13398-B5C6-43EB-8806-DA9F8E08977D} = {45820ABF-31FB-48DD-8BFF-694764BDB994}
{2426D84A-348B-4B4C-BE06-1A2CDDB6A3AA} = {45820ABF-31FB-48DD-8BFF-694764BDB994}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AE4B10C2-1C94-400B-8F33-2C254A9E1E1A}
Expand Down
8 changes: 4 additions & 4 deletions src/FG.Utils.BuildTools/FG.Utils.BuildTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
<PackageProjectUrl>https://github.com/FabricatorsGuild/FG.Utils</PackageProjectUrl>
<PackageIconUrl>https://raw.githubusercontent.com/FabricatorsGuild/FG.Utils/master/fg.logo.png</PackageIconUrl>
<RepositoryUrl>https://github.com/FabricatorsGuild/FG.Utils</RepositoryUrl>
<PackageReleaseNotes>Added support for adding/removing project files</PackageReleaseNotes>
<Version>1.2.0</Version>
<AssemblyVersion>1.2.0.0</AssemblyVersion>
<FileVersion>1.2.0.0</FileVersion>
<PackageReleaseNotes>Added support for determining the default OutputPath for both classic and CPS project</PackageReleaseNotes>
<Version>1.2.1</Version>
<AssemblyVersion>1.2.1.0</AssemblyVersion>
<FileVersion>1.2.1.0</FileVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="System.IO.Compression" />
Expand Down
54 changes: 54 additions & 0 deletions src/FG.Utils.BuildTools/ProjectTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1479,5 +1479,59 @@ private void RemoveFileFromCPSProject(string path)
_didUpdateDocument = true;
}
}

public string GetProjectOutputPath(string configuration, string platform)
{
if (!_isCpsDocument)
{
return GetClassicProjectOutputPath(configuration, platform);
}
else
{
return GetCPSProjectOutputPath(configuration, platform);
}
}

private string GetDefaultOutputPath(string configuration, string platform)
{
return (string.IsNullOrWhiteSpace(platform) || platform == "AnyCPU")
? $"bin\\{configuration}"
: $"bin\\{platform}\\{configuration}";
}


private string GetClassicProjectOutputPath(string configuration, string platform)
{
var projectProperties = GetClassicProjectProperties(configuration, platform);
if (projectProperties.ContainsKey("OutputPath"))
{
return projectProperties["OutputPath"];
}
return GetDefaultOutputPath(configuration, platform);
}

private string GetCPSProjectOutputPath(string configuration, string platform)
{
var projectProperties = GetCPSProjectProperties(configuration, platform);

var outputPath = projectProperties.Get("OutputPath") ?? GetDefaultOutputPath(configuration, platform);
var targetFramework = projectProperties.Get("TargetFramework");
var platformTarget = projectProperties.Get("PlatformTarget");
var runtimeIdentifier = projectProperties.Get("RuntimeIdentifier");

if (targetFramework != null)
{
outputPath = $"{outputPath}\\{targetFramework}";
}

if (runtimeIdentifier != null)
{
outputPath = $"{outputPath}\\{runtimeIdentifier}";
}

return outputPath;
}


}
}
57 changes: 55 additions & 2 deletions src/testing/FG.Utils.BuildTools.Tests/ProjectTool_tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ public class ProjectTool_tests
private const string CPSProjectRelativePath =
@"../../../../../samples/Ce.Labs.Samples.CPSProject/Ce.Labs.Samples.CPSProject.csproj";

private IList<string> _temporaryProjectFileCopies = new List<string>();
private const string CPSProjectRelativePathNoOutputPath =
@"../../../../../samples/Ce.Labs.Samples.CPSProjectNoOutputPath/Ce.Labs.Samples.CPSProjectNoOutputPath.csproj";
private const string CPSProjectRelativePathNoOutputPathNoRuntime =
@"../../../../../samples/Ce.Labs.Samples.CPSProjectNoOutputPathNoRuntime/Ce.Labs.Samples.CPSProjectNoOutputPathNoRuntime.csproj";
private const string CPSProjectRelativePathNoOutputPathx64 =
@"../../../../../samples/Ce.Labs.Samples.CPSProjectNoOutputPathx64/Ce.Labs.Samples.CPSProjectNoOutputPathx64.csproj";
private const string CPSProjectRelativePathNoOutputPathx64NoRuntime =
@"../../../../../samples/Ce.Labs.Samples.CPSProjectNoOutputPathx64NoRuntime/Ce.Labs.Samples.CPSProjectNoOutputPathx64NoRuntime.csproj";


private readonly IList<string> _temporaryProjectFileCopies = new List<string>();

[TearDown]
public void TearDown()
Expand Down Expand Up @@ -248,7 +258,6 @@ private void Should_be_able_to_add_excluded_file_with_properties_to_project(stri
);
}


private void Should_be_able_to_remove_file_without_properties_from_project(string projectRelativePath)
{
var projectTool = TempCopyAndGetProject(projectRelativePath);
Expand Down Expand Up @@ -282,6 +291,14 @@ private void Should_be_able_to_remove_file_without_properties_from_project(strin
);
}

private void Should_be_able_to_determine_output_path_for_project(string projectRelativePath, string configuration, string platform, string expectedOutputPath)
{
var projectTool = TempCopyAndGetProject(projectRelativePath);

var outputPath = projectTool.GetProjectOutputPath(configuration, platform);

outputPath.Should().Be(expectedOutputPath);
}

[Test]
public void Should_be_able_to_load_files_in_classic_project()
Expand Down Expand Up @@ -401,5 +418,41 @@ public void Should_be_able_to_remove_file_without_properties_from_cps_project()
{
Should_be_able_to_remove_file_without_properties_from_project(CPSProjectRelativePath);
}

[Test]
public void Should_be_able_to_determine_output_path_for_classic_project()
{
Should_be_able_to_determine_output_path_for_project(ClassicProjectRelativePath, "Debug", "AnyCPU", @"bin\Debug\special_bin\");
Should_be_able_to_determine_output_path_for_project(ClassicProjectRelativePath, "Debug", "x64", @"bin\x64\Debug");
Should_be_able_to_determine_output_path_for_project(ClassicProjectRelativePath, "Release", "AnyCPU", @"bin\Release\special_releaseBin");
Should_be_able_to_determine_output_path_for_project(ClassicProjectRelativePath, "Release", "x64", @"bin\x64\Release");
}

[Test]
public void Should_be_able_to_determine_output_path_for_CPS_project()
{
Should_be_able_to_determine_output_path_for_project(CPSProjectRelativePath, "Debug", "AnyCPU", @"bin\Debug\net461\win7-x64\special_bin\net461\win7-x64");
Should_be_able_to_determine_output_path_for_project(CPSProjectRelativePath, "Release", "AnyCPU", @"bin\Release\net461\win7-x64");

Should_be_able_to_determine_output_path_for_project(CPSProjectRelativePathNoOutputPath, "Debug", "AnyCPU", @"bin\Debug\net461");
Should_be_able_to_determine_output_path_for_project(CPSProjectRelativePathNoOutputPath, "Release", "AnyCPU", @"bin\Release\net461");
Should_be_able_to_determine_output_path_for_project(CPSProjectRelativePathNoOutputPath, "Debug", "x64", @"bin\x64\Debug\net461");
Should_be_able_to_determine_output_path_for_project(CPSProjectRelativePathNoOutputPath, "Release", "x64", @"bin\x64\Release\net461");

Should_be_able_to_determine_output_path_for_project(CPSProjectRelativePathNoOutputPathNoRuntime, "Debug", "AnyCPU", @"bin\Debug\net461");
Should_be_able_to_determine_output_path_for_project(CPSProjectRelativePathNoOutputPathNoRuntime, "Release", "AnyCPU", @"bin\Release\net461");
Should_be_able_to_determine_output_path_for_project(CPSProjectRelativePathNoOutputPathNoRuntime, "Debug", "x64", @"bin\x64\Debug\net461");
Should_be_able_to_determine_output_path_for_project(CPSProjectRelativePathNoOutputPathNoRuntime, "Release", "x64", @"bin\x64\Release\net461");

Should_be_able_to_determine_output_path_for_project(CPSProjectRelativePathNoOutputPathx64, "Debug", "AnyCPU", @"bin\Debug\net461\win7-x64");
Should_be_able_to_determine_output_path_for_project(CPSProjectRelativePathNoOutputPathx64, "Release", "AnyCPU", @"bin\Release\net461\win7-x64");
Should_be_able_to_determine_output_path_for_project(CPSProjectRelativePathNoOutputPathx64, "Debug", "x64", @"bin\x64\Debug\net461\win7-x64");
Should_be_able_to_determine_output_path_for_project(CPSProjectRelativePathNoOutputPathx64, "Release", "x64", @"bin\x64\Release\net461\win7-x64");

Should_be_able_to_determine_output_path_for_project(CPSProjectRelativePathNoOutputPathx64NoRuntime, "Debug", "AnyCPU", @"bin\Debug\net461");
Should_be_able_to_determine_output_path_for_project(CPSProjectRelativePathNoOutputPathx64NoRuntime, "Release", "AnyCPU", @"bin\Release\net461");
Should_be_able_to_determine_output_path_for_project(CPSProjectRelativePathNoOutputPathx64NoRuntime, "Debug", "x64", @"bin\x64\Debug\net461");
Should_be_able_to_determine_output_path_for_project(CPSProjectRelativePathNoOutputPathx64NoRuntime, "Release", "x64", @"bin\x64\Release\net461");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<SkipValidatePackageReferences>true</SkipValidatePackageReferences>
<Company>Code Effect</Company>
<OutputType>Library</OutputType>
<Authors>Code Effect</Authors>
<Product>CE Labs</Product>
<Description>Sample project for running testing CE Labs BuildTools</Description>
<RootNamespace>Ce.Labs.Samples</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Ce.Labs.Samples
{
public class SampleClass1IncludedInproject
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<SkipValidatePackageReferences>true</SkipValidatePackageReferences>
<Platforms>AnyCPU;x64</Platforms>
<Company>Code Effect</Company>
<OutputType>Library</OutputType>
<Authors>Code Effect</Authors>
<Product>CE Labs</Product>
<Description>Sample project for running testing CE Labs BuildTools</Description>
<RootNamespace>Ce.Labs.Samples</RootNamespace>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Ce.Labs.Samples
{
public class SampleClass1IncludedInproject
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<RuntimeIdentifier>win7-x64</RuntimeIdentifier>
<SkipValidatePackageReferences>true</SkipValidatePackageReferences>
<Platforms>AnyCPU;x64</Platforms>
<Company>Code Effect</Company>
<OutputType>Library</OutputType>
<Authors>Code Effect</Authors>
<Product>CE Labs</Product>
<Description>Sample project for running testing CE Labs BuildTools</Description>
<RootNamespace>Ce.Labs.Samples</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Ce.Labs.Samples
{
public class SampleClass1IncludedInproject
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<SkipValidatePackageReferences>true</SkipValidatePackageReferences>
<Company>Code Effect</Company>
<OutputType>Library</OutputType>
<Authors>Code Effect</Authors>
<Product>CE Labs</Product>
<Description>Sample project for running testing CE Labs BuildTools</Description>
<RootNamespace>Ce.Labs.Samples</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Ce.Labs.Samples
{
public class SampleClass1IncludedInproject
{
}
}
Loading

0 comments on commit 3039e5e

Please sign in to comment.