Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert MSBuildLocator change #338

Closed
wants to merge 2 commits into from
Closed
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
30 changes: 11 additions & 19 deletions src/NerdBank.GitVersioning.Tests/AssemblyInfoTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,20 @@
using Nerdbank.GitVersioning.Tasks;
using Xunit;

namespace NerdBank.GitVersioning.Tests
public class AssemblyInfoTest
{
public class AssemblyInfoTest
[Fact]
public void FSharpGenerator()
{
public AssemblyInfoTest()
{
MSBuildExtensions.LoadMSBuild();
}
var info = new AssemblyVersionInfo();
info.AssemblyCompany = "company";
info.AssemblyFileVersion = "1.3.1.0";
info.AssemblyVersion = "1.3.0.0";
info.CodeLanguage = "f#";

[Fact]
public void FSharpGenerator()
{
var info = new AssemblyVersionInfo();
info.AssemblyCompany = "company";
info.AssemblyFileVersion = "1.3.1.0";
info.AssemblyVersion = "1.3.0.0";
info.CodeLanguage = "f#";

var built = info.BuildCode();
var built = info.BuildCode();

var expected = @"//------------------------------------------------------------------------------
var expected = @"//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
Expand All @@ -49,7 +42,6 @@ type internal ThisAssembly() =
static member internal RootNamespace = """"
do()
";
Assert.Equal(expected, built);
}
Assert.Equal(expected, built);
}
}
3 changes: 0 additions & 3 deletions src/NerdBank.GitVersioning.Tests/BuildIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Nerdbank.GitVersioning;
using Nerdbank.GitVersioning.Tests;
using Validation;
using Xunit;
using Xunit.Abstractions;
Expand Down Expand Up @@ -49,8 +48,6 @@ public class BuildIntegrationTests : RepoTestBase
public BuildIntegrationTests(ITestOutputHelper logger)
: base(logger)
{
MSBuildExtensions.LoadMSBuild();

int seed = (int)DateTime.Now.Ticks;
this.random = new Random(seed);
this.Logger.WriteLine("Random seed: {0}", seed);
Expand Down
1 change: 0 additions & 1 deletion src/NerdBank.GitVersioning.Tests/GitExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Threading.Tasks;
using LibGit2Sharp;
using Nerdbank.GitVersioning;
using Nerdbank.GitVersioning.Tests;
using Validation;
using Xunit;
using Xunit.Abstractions;
Expand Down
16 changes: 0 additions & 16 deletions src/NerdBank.GitVersioning.Tests/MSBuildExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,12 @@
using Microsoft.Build.Evaluation;
using Microsoft.Build.Execution;
using Microsoft.Build.Framework;
using Microsoft.Build.Locator;
using Microsoft.Build.Logging;
using Validation;
using Xunit.Abstractions;

internal static class MSBuildExtensions
{
private static readonly object loadLock = new object();
private static bool loaded;

internal static void LoadMSBuild()
{
lock (loadLock)
{
if (!loaded)
{
MSBuildLocator.RegisterDefaults();
loaded = true;
}
}
}

internal static async Task<BuildResult> BuildAsync(this BuildManager buildManager, ITestOutputHelper logger, ProjectCollection projectCollection, ProjectRootElement project, string target, IDictionary<string, string> globalProperties = null, LoggerVerbosity logVerbosity = LoggerVerbosity.Detailed, ILogger[] additionalLoggers = null)
{
Requires.NotNull(buildManager, nameof(buildManager));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
<PackageReference Include="7z.NET" Version="1.0.3" />
<PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.10" />
<PackageReference Include="System.Collections.Immutable" Version="1.5.0" />
<PackageReference Include="Microsoft.Build" Version="15.1.548" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.1.548" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Locator" Version="1.2.2" />
<PackageReference Include="Microsoft.Build" Version="15.9.20" Condition=" '$(TargetFramework)' == 'net461' " />
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="4.9.0" />
<PackageReference Include="Xunit.Combinatorial" Version="1.2.7" />
<PackageReference Include="xunit" Version="2.4.1" />
Expand All @@ -45,7 +43,11 @@
</PackageReference>
<PackageReference Include="Xunit.SkippableFact" Version="1.3.12" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net461' ">
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="15.9.20" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="15.1.548" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
</ItemGroup>
</Project>
1 change: 0 additions & 1 deletion src/NerdBank.GitVersioning.Tests/ReleaseManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Linq;
using LibGit2Sharp;
using Nerdbank.GitVersioning;
using Nerdbank.GitVersioning.Tests;
using Xunit;
using Xunit.Abstractions;

Expand Down
214 changes: 106 additions & 108 deletions src/NerdBank.GitVersioning.Tests/RepoTestBase.cs
Original file line number Diff line number Diff line change
@@ -1,152 +1,150 @@
namespace Nerdbank.GitVersioning.Tests
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LibGit2Sharp;
using Nerdbank.GitVersioning;
using Validation;
using Xunit.Abstractions;

public abstract class RepoTestBase : IDisposable
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LibGit2Sharp;
using Validation;
using Xunit.Abstractions;

public abstract class RepoTestBase : IDisposable
{
private readonly List<string> repoDirectories = new List<string>();
private readonly List<string> repoDirectories = new List<string>();

public RepoTestBase(ITestOutputHelper logger)
{
Requires.NotNull(logger, nameof(logger));
public RepoTestBase(ITestOutputHelper logger)
{
Requires.NotNull(logger, nameof(logger));

this.Logger = logger;
this.RepoPath = this.CreateDirectoryForNewRepo();
}
this.Logger = logger;
this.RepoPath = this.CreateDirectoryForNewRepo();
}

protected ITestOutputHelper Logger { get; }
protected ITestOutputHelper Logger { get; }

protected Repository Repo { get; set; }
protected Repository Repo { get; set; }

protected string RepoPath { get; set; }
protected string RepoPath { get; set; }

protected Signature Signer => new Signature("a", "[email protected]", new DateTimeOffset(2015, 8, 2, 0, 0, 0, TimeSpan.Zero));
protected Signature Signer => new Signature("a", "[email protected]", new DateTimeOffset(2015, 8, 2, 0, 0, 0, TimeSpan.Zero));

public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}

protected string CreateDirectoryForNewRepo()
protected string CreateDirectoryForNewRepo()
{
string repoPath;
do
{
string repoPath;
do
{
repoPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
} while (Directory.Exists(repoPath));
Directory.CreateDirectory(repoPath);
repoPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
} while (Directory.Exists(repoPath));
Directory.CreateDirectory(repoPath);

this.repoDirectories.Add(repoPath);
return repoPath;
}
this.repoDirectories.Add(repoPath);
return repoPath;
}

protected virtual void Dispose(bool disposing)
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if (disposing)
this.Repo?.Dispose();
foreach (string dir in this.repoDirectories)
{
this.Repo?.Dispose();
foreach (string dir in this.repoDirectories)
try
{
TestUtilities.DeleteDirectory(dir);
}
catch (IOException)
{
try
{
TestUtilities.DeleteDirectory(dir);
}
catch (IOException)
{
// This happens in AppVeyor a lot.
}
// This happens in AppVeyor a lot.
}
}
}
}

protected void InitializeSourceControl()
protected void InitializeSourceControl()
{
Repository.Init(this.RepoPath);
this.Repo = new Repository(this.RepoPath);
foreach (var file in this.Repo.RetrieveStatus().Untracked)
{
Repository.Init(this.RepoPath);
this.Repo = new Repository(this.RepoPath);
foreach (var file in this.Repo.RetrieveStatus().Untracked)
{
Commands.Stage(this.Repo, file.FilePath);
}

if (this.Repo.Index.Count > 0)
{
this.Repo.Commit("initial commit", this.Signer, this.Signer);
}
Commands.Stage(this.Repo, file.FilePath);
}

protected void AddCommits(int count = 1)
if (this.Repo.Index.Count > 0)
{
Verify.Operation(this.Repo != null, "Repo has not been created yet.");
for (int i = 1; i <= count; i++)
{
this.Repo.Commit($"filler commit {i}", this.Signer, this.Signer, new CommitOptions { AllowEmptyCommit = true });
}
this.Repo.Commit("initial commit", this.Signer, this.Signer);
}
}

protected Commit WriteVersionTxtFile(string version = "1.2", string prerelease = "", string relativeDirectory = null)
protected void AddCommits(int count = 1)
{
Verify.Operation(this.Repo != null, "Repo has not been created yet.");
for (int i = 1; i <= count; i++)
{
if (relativeDirectory == null)
{
relativeDirectory = string.Empty;
}

string versionFilePath = Path.Combine(this.RepoPath, relativeDirectory, "version.txt");
File.WriteAllText(versionFilePath, $"{version}\r\n{prerelease}");
return this.CommitVersionFile(versionFilePath, $"{version}{prerelease}");
this.Repo.Commit($"filler commit {i}", this.Signer, this.Signer, new CommitOptions { AllowEmptyCommit = true });
}
}

protected Commit WriteVersionFile(string version = "1.2", string prerelease = "", string relativeDirectory = null)
protected Commit WriteVersionTxtFile(string version = "1.2", string prerelease = "", string relativeDirectory = null)
{
if (relativeDirectory == null)
{
var versionData = VersionOptions.FromVersion(new System.Version(version), prerelease);
return this.WriteVersionFile(versionData, relativeDirectory);
relativeDirectory = string.Empty;
}

protected Commit WriteVersionFile(VersionOptions versionData, string relativeDirectory = null)
{
Requires.NotNull(versionData, nameof(versionData));
string versionFilePath = Path.Combine(this.RepoPath, relativeDirectory, "version.txt");
File.WriteAllText(versionFilePath, $"{version}\r\n{prerelease}");
return this.CommitVersionFile(versionFilePath, $"{version}{prerelease}");
}

if (relativeDirectory == null)
{
relativeDirectory = string.Empty;
}
protected Commit WriteVersionFile(string version = "1.2", string prerelease = "", string relativeDirectory = null)
{
var versionData = VersionOptions.FromVersion(new System.Version(version), prerelease);
return this.WriteVersionFile(versionData, relativeDirectory);
}

string versionFilePath = VersionFile.SetVersion(Path.Combine(this.RepoPath, relativeDirectory), versionData);
return this.CommitVersionFile(versionFilePath, versionData.Version?.ToString());
}
protected Commit WriteVersionFile(VersionOptions versionData, string relativeDirectory = null)
{
Requires.NotNull(versionData, nameof(versionData));

protected Commit CommitVersionFile(string versionFilePath, string version)
if (relativeDirectory == null)
{
Requires.NotNullOrEmpty(versionFilePath, nameof(versionFilePath));
Requires.NotNullOrEmpty(versionFilePath, nameof(versionFilePath));
relativeDirectory = string.Empty;
}

string versionFilePath = VersionFile.SetVersion(Path.Combine(this.RepoPath, relativeDirectory), versionData);
return this.CommitVersionFile(versionFilePath, versionData.Version?.ToString());
}

protected Commit CommitVersionFile(string versionFilePath, string version)
{
Requires.NotNullOrEmpty(versionFilePath, nameof(versionFilePath));
Requires.NotNullOrEmpty(versionFilePath, nameof(versionFilePath));

if (this.Repo != null)
if (this.Repo != null)
{
Assumes.True(versionFilePath.StartsWith(this.RepoPath, StringComparison.OrdinalIgnoreCase));
var relativeFilePath = versionFilePath.Substring(this.RepoPath.Length).TrimStart(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
Commands.Stage(this.Repo, relativeFilePath);
if (Path.GetExtension(relativeFilePath) == ".json")
{
Assumes.True(versionFilePath.StartsWith(this.RepoPath, StringComparison.OrdinalIgnoreCase));
var relativeFilePath = versionFilePath.Substring(this.RepoPath.Length).TrimStart(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
Commands.Stage(this.Repo, relativeFilePath);
if (Path.GetExtension(relativeFilePath) == ".json")
string txtFilePath = relativeFilePath.Substring(0, relativeFilePath.Length - 4) + "txt";
if (!File.Exists(Path.Combine(this.RepoPath, txtFilePath)) && this.Repo.Index[txtFilePath] != null)
{
string txtFilePath = relativeFilePath.Substring(0, relativeFilePath.Length - 4) + "txt";
if (!File.Exists(Path.Combine(this.RepoPath, txtFilePath)) && this.Repo.Index[txtFilePath] != null)
{
this.Repo.Index.Remove(txtFilePath);
}
this.Repo.Index.Remove(txtFilePath);
}

return this.Repo.Commit($"Add/write {relativeFilePath} set to {version ?? "Inherited"}", this.Signer, this.Signer, new CommitOptions { AllowEmptyCommit = true });
}

return null;
return this.Repo.Commit($"Add/write {relativeFilePath} set to {version ?? "Inherited"}", this.Signer, this.Signer, new CommitOptions { AllowEmptyCommit = true });
}

return null;
}
}
Loading