Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class CsProjClassicNetToolchain : Toolchain

private CsProjClassicNetToolchain(string targetFrameworkMoniker, string name, string packagesPath = null, TimeSpan? timeout = null)
: base(name,
new CsProjGenerator(targetFrameworkMoniker, cliPath: null, packagesPath: packagesPath, runtimeFrameworkVersion: null),
new CsProjGenerator(targetFrameworkMoniker, cliPath: null, packagesPath: packagesPath, runtimeFrameworkVersion: null, isNetCore: false),
new DotNetCliBuilder(targetFrameworkMoniker, customDotNetCliPath: null, timeout: timeout),
new Executor())
{
Expand Down
4 changes: 2 additions & 2 deletions src/BenchmarkDotNet/Toolchains/CsProj/CsProjGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public class CsProjGenerator : DotNetCliGenerator

public string RuntimeFrameworkVersion { get; }

public CsProjGenerator(string targetFrameworkMoniker, string cliPath, string packagesPath, string runtimeFrameworkVersion)
: base(targetFrameworkMoniker, cliPath, packagesPath)
public CsProjGenerator(string targetFrameworkMoniker, string cliPath, string packagesPath, string runtimeFrameworkVersion, bool isNetCore = true)
: base(targetFrameworkMoniker, cliPath, packagesPath, isNetCore)
{
RuntimeFrameworkVersion = runtimeFrameworkVersion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ public abstract class DotNetCliGenerator : GeneratorBase

[PublicAPI] public string PackagesPath { get; }

protected bool IsNetCore { get; }

[PublicAPI]
protected DotNetCliGenerator(string targetFrameworkMoniker, string cliPath, string packagesPath)
protected DotNetCliGenerator(string targetFrameworkMoniker, string cliPath, string packagesPath, bool isNetCore)
{
TargetFrameworkMoniker = targetFrameworkMoniker;
CliPath = cliPath;
PackagesPath = packagesPath;
IsNetCore = isNetCore;
}

protected override string GetExecutableExtension() => TargetFrameworkMoniker.Contains("core") ? ".dll" : ".exe";
protected override string GetExecutableExtension() => IsNetCore ? ".dll" : ".exe";

/// <summary>
/// we need our folder to be on the same level as the project that we want to reference
Expand Down
29 changes: 15 additions & 14 deletions tests/BenchmarkDotNet.Tests/CsProjGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ public class CsProjGeneratorTests
private FileInfo TestAssemblyFileInfo = new FileInfo(typeof(CsProjGeneratorTests).Assembly.Location);

[Theory]
[InlineData("net471")]
[InlineData("netcoreapp3.0")]
public void ItsPossibleToCustomizeProjectSdkBasedOnProjectSdkFromTheProjectFile(string targetFrameworkMoniker)
[InlineData("net471", false)]
[InlineData("netcoreapp3.0", true)]
public void ItsPossibleToCustomizeProjectSdkBasedOnProjectSdkFromTheProjectFile(string targetFrameworkMoniker, bool isNetCore)
{
const string withCustomProjectSdk = @"
<Project Sdk=""CUSTOM"">
</Project>
";
AssertParsedSdkName(withCustomProjectSdk, targetFrameworkMoniker, "CUSTOM");
AssertParsedSdkName(withCustomProjectSdk, targetFrameworkMoniker, "CUSTOM", isNetCore);
}

[Fact]
Expand All @@ -37,7 +37,7 @@ public void ItsImpossibleToCustomizeProjectSdkForFullFrameworkAppsBasedOnTheImpo
<Import Sdk=""Microsoft.NET.Sdk.WindowsDesktop"" Project=""Sdk.props"" Condition=""'$(TargetFramework)'=='netcoreapp3.0'""/>
</Project>
";
AssertParsedSdkName(withCustomProjectImport, "net471", "Microsoft.NET.Sdk");
AssertParsedSdkName(withCustomProjectImport, "net471", "Microsoft.NET.Sdk", false);
}

[Fact]
Expand All @@ -48,13 +48,13 @@ public void ItsPossibleToCustomizeProjectSdkForNetCoreAppsBasedOnTheImportOfSdk(
<Import Sdk=""Microsoft.NET.Sdk.WindowsDesktop"" Project=""Sdk.props"" Condition=""'$(TargetFramework)'=='netcoreapp3.0'""/>
</Project>
";
AssertParsedSdkName(withCustomProjectImport, "netcoreapp3.0", "Microsoft.NET.Sdk.WindowsDesktop");
AssertParsedSdkName(withCustomProjectImport, "netcoreapp3.0", "Microsoft.NET.Sdk.WindowsDesktop", true);
}

[AssertionMethod]
private void AssertParsedSdkName(string csProjContent, string targetFrameworkMoniker, string expectedSdkValue)
private void AssertParsedSdkName(string csProjContent, string targetFrameworkMoniker, string expectedSdkValue, bool isNetCore)
{
var sut = new CsProjGenerator(targetFrameworkMoniker, null, null, null);
var sut = new CsProjGenerator(targetFrameworkMoniker, null, null, null, isNetCore);

using (var reader = new StringReader(csProjContent))
{
Expand All @@ -76,7 +76,7 @@ public void UseWpfSettingGetsCopied()
</PropertyGroup>
</Project>
";
var sut = new CsProjGenerator("netcoreapp3.0", null, null, null);
var sut = new CsProjGenerator("netcoreapp3.0", null, null, null, true);

using (var reader = new StringReader(withUseWpfTrue))
{
Expand Down Expand Up @@ -105,7 +105,7 @@ public void SettingsFromPropsFileImportedUsingAbsolutePathGetCopies()
<Import Project=""{propsFilePath}"" />
</Project>";

var sut = new CsProjGenerator("netcoreapp3.0", null, null, null);
var sut = new CsProjGenerator("netcoreapp3.0", null, null, null, true);

using (var reader = new StringReader(importingAbsolutePath))
{
Expand Down Expand Up @@ -136,7 +136,7 @@ public void SettingsFromPropsFileImportedUsingRelativePathGetCopies()
<Import Project="".{Path.DirectorySeparatorChar}test.props"" />
</Project>";

var sut = new CsProjGenerator("netcoreapp3.0", null, null, null);
var sut = new CsProjGenerator("netcoreapp3.0", null, null, null, true);

using (var reader = new StringReader(importingRelativePath))
{
Expand Down Expand Up @@ -170,7 +170,7 @@ public void TheDefaultFilePathShouldBeUsedWhenAnAssemblyLocationIsEmpty()
var benchmarkCase = BenchmarkCase.Create(target, Job.Default, null, config);

var benchmarks = new[] { new BenchmarkBuildInfo(benchmarkCase, config.CreateImmutableConfig(), 999) };
var projectGenerator = new SteamLoadedBuildPartition("netcoreapp3.0", null, null, null);
var projectGenerator = new SteamLoadedBuildPartition("netcoreapp3.0", null, null, null, true);
string binariesPath = projectGenerator.ResolvePathForBinaries(new BuildPartition(benchmarks, new Resolver()), programName);

string expectedPath = Path.Combine(Path.Combine(Directory.GetCurrentDirectory(), "BenchmarkDotNet.Bin"), programName);
Expand All @@ -189,7 +189,7 @@ public void TestAssemblyFilePathIsUsedWhenTheAssemblyLocationIsNotEmpty()
var target = new Descriptor(typeof(MockFactory.MockBenchmarkClass), benchmarkMethod);
var benchmarkCase = BenchmarkCase.Create(target, Job.Default, null, ManualConfig.CreateEmpty().CreateImmutableConfig());
var benchmarks = new[] { new BenchmarkBuildInfo(benchmarkCase, ManualConfig.CreateEmpty().CreateImmutableConfig(), 0) };
var projectGenerator = new SteamLoadedBuildPartition("netcoreapp3.0", null, null, null);
var projectGenerator = new SteamLoadedBuildPartition("netcoreapp3.0", null, null, null, true);
var buildPartition = new BuildPartition(benchmarks, new Resolver());
string binariesPath = projectGenerator.ResolvePathForBinaries(buildPartition, programName);

Expand All @@ -204,7 +204,8 @@ internal string ResolvePathForBinaries(BuildPartition buildPartition, string pro
return base.GetBuildArtifactsDirectoryPath(buildPartition, programName);
}

public SteamLoadedBuildPartition(string targetFrameworkMoniker, string cliPath, string packagesPath, string runtimeFrameworkVersion) : base(targetFrameworkMoniker, cliPath, packagesPath, runtimeFrameworkVersion) { }
public SteamLoadedBuildPartition(string targetFrameworkMoniker, string cliPath, string packagesPath, string runtimeFrameworkVersion, bool isNetCore)
: base(targetFrameworkMoniker, cliPath, packagesPath, runtimeFrameworkVersion, isNetCore) { }
}
}
}