本文整理汇总了C#中SemanticVersion类的典型用法代码示例。如果您正苦于以下问题:C# SemanticVersion类的具体用法?C# SemanticVersion怎么用?C# SemanticVersion使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SemanticVersion类属于命名空间,在下文中一共展示了SemanticVersion类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PutAsync
public async Task<Hash> PutAsync(long id, SemanticVersion version, IPackage package)
{
#region Preconditions
if (package == null) throw new ArgumentNullException(nameof(package));
#endregion
var key = id.ToString() + "/" + version.ToString();
using (var ms = new MemoryStream())
{
await package.ZipToStreamAsync(ms).ConfigureAwait(false);
var hash = Hash.ComputeSHA256(ms, leaveOpen: true);
var blob = new Blob(ms) {
ContentType = "application/zip"
};
await bucket.PutAsync(key, blob).ConfigureAwait(false);
return hash;
}
}
示例2: VersionString_carried_through_even_if_invalid
public void VersionString_carried_through_even_if_invalid()
{
// Ensure the version string is available, even if the value is not a valid SemVer
SemanticVersion semVer = new SemanticVersion("1.2.3*3.2213312-invalid");
Assert.Equal("1.2.3*3.2213312-invalid", semVer.VersionString);
Assert.False(semVer.IsValid);
}
示例3: Matches
public static bool Matches(IVersionSpec versionSpec, SemanticVersion version)
{
if (versionSpec == null)
return true; // I CAN'T DEAL WITH THIS
bool minVersion;
if (versionSpec.MinVersion == null) {
minVersion = true; // no preconditon? LET'S DO IT
} else if (versionSpec.IsMinInclusive) {
minVersion = version >= versionSpec.MinVersion;
} else {
minVersion = version > versionSpec.MinVersion;
}
bool maxVersion;
if (versionSpec.MaxVersion == null) {
maxVersion = true; // no preconditon? LET'S DO IT
} else if (versionSpec.IsMaxInclusive) {
maxVersion = version <= versionSpec.MaxVersion;
} else {
maxVersion = version < versionSpec.MaxVersion;
}
return maxVersion && minVersion;
}
示例4: GetHashCode
public int GetHashCode(SemanticVersion obj)
{
var version = obj as NuGetVersion;
return String.Format(CultureInfo.InvariantCulture, "{0}.{1}.{2}-{3}GIT{4}",
version.Major, version.Minor, version.Patch, version.Release, GetCommitFromMetadata(version.Metadata)).GetHashCode();
}
示例5: CreatePackageReference
void CreatePackageReference (
string packageId = "Id",
bool requireReinstallation = false)
{
var version = new SemanticVersion ("1.2.3");
packageReference = new PackageReference (packageId, version, null, null, false, requireReinstallation);
}
示例6: BumpPatchVersion
public void BumpPatchVersion()
{
var semver = new SemanticVersion(Version);
var newVer = new SemanticVersion(semver.Major, semver.Minor, semver.Patch+1,build:null, preRelease: null);
Version = FileVersion = newVer.ToString();
}
示例7: AssertVariablesAreWrittenToFile
static void AssertVariablesAreWrittenToFile(string f)
{
var writes = new List<string>();
var semanticVersion = new SemanticVersion
{
Major = 1,
Minor = 2,
Patch = 3,
PreReleaseTag = "beta1",
BuildMetaData = "5"
};
semanticVersion.BuildMetaData.CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z");
semanticVersion.BuildMetaData.Sha = "commitSha";
var config = new TestEffectiveConfiguration();
var variables = VariableProvider.GetVariablesFor(semanticVersion, config, false);
var j = new Jenkins(f);
j.WriteIntegration(writes.Add, variables);
writes[1].ShouldBe("1.2.3-beta.1+5");
File.Exists(f).ShouldBe(true);
var props = File.ReadAllText(f);
props.ShouldContain("GitVersion_Major=1");
props.ShouldContain("GitVersion_Minor=2");
}
示例8: VerifyCreatedCode
public void VerifyCreatedCode()
{
var semanticVersion = new SemanticVersion
{
Major = 1,
Minor = 2,
Patch = 3,
PreReleaseTag = "unstable4",
BuildMetaData = new SemanticVersionBuildMetaData(5,
"feature1",
new ReleaseDate
{
OriginalCommitSha = "originalCommitSha",
OriginalDate = DateTimeOffset.Parse("2014-03-01 00:00:01Z"),
CommitSha = "commitSha",
Date = DateTimeOffset.Parse("2014-03-06 23:59:59Z")
})
};
var assemblyInfoBuilder = new AssemblyInfoBuilder
{
SemanticVersion = semanticVersion
};
var assemblyInfoText = assemblyInfoBuilder.GetAssemblyInfoText();
Approvals.Verify(assemblyInfoText);
var syntaxTree = SyntaxTree.ParseText(assemblyInfoText);
var references = new[] {new MetadataFileReference(typeof(object).Assembly.Location), };
var compilation = Compilation.Create("Greeter.dll", new CompilationOptions(OutputKind.NetModule), new[] { syntaxTree }, references);
var emitResult = compilation.Emit(new MemoryStream());
Assert.IsTrue(emitResult.Success, string.Join(Environment.NewLine, emitResult.Diagnostics.Select(x => x.Info)));
}
示例9: remove_hook_should_be_called
protected void remove_hook_should_be_called(string expectedRepository, string expectedName, string expectedScope, SemanticVersion expectedVersion)
{
RemoveCalls.FirstOrDefault(x => x.Repository == expectedRepository &&
x.Name == expectedName &&
x.Scope == expectedScope &&
x.Version == expectedVersion).ShouldNotBeNull();
}
示例10: GetHashCodeNotEqualNoBuildNoPrerelease
public void GetHashCodeNotEqualNoBuildNoPrerelease()
{
SemanticVersion left = new SemanticVersion(1, 0, 0);
SemanticVersion right = new SemanticVersion(2, 0, 0);
Assert.NotEqual(left.GetHashCode(), right.GetHashCode());
}
示例11: GetHashCodeNotEqual
public void GetHashCodeNotEqual()
{
SemanticVersion left = new SemanticVersion(1, 0, 0, "foo", "bar");
SemanticVersion right = new SemanticVersion(2, 0, 0, "foo", "bar");
Assert.NotEqual(left.GetHashCode(), right.GetHashCode());
}
示例12: TryGetVersion
public static bool TryGetVersion(string directory, out SemanticVersion versionAndBranch)
{
var gitDirectory = GitDirFinder.TreeWalkForGitDir(directory);
if (string.IsNullOrEmpty(gitDirectory))
{
var message =
"No .git directory found in provided solution path. This means the assembly may not be versioned correctly. " +
"To fix this warning either clone the repository using git or remove the `GitVersionTask` nuget package. " +
"To temporarily work around this issue add a AssemblyInfo.cs with an appropriate `AssemblyVersionAttribute`. " +
"If it is detected that this build is occurring on a CI server an error may be thrown.";
Logger.WriteWarning(message);
versionAndBranch = null;
return false;
}
if (!processedDirectories.Contains(directory))
{
processedDirectories.Add(directory);
var authentication = new Authentication();
foreach (var buildServer in BuildServerList.GetApplicableBuildServers(authentication))
{
Logger.WriteInfo(string.Format("Executing PerformPreProcessingSteps for '{0}'.", buildServer.GetType().Name));
buildServer.PerformPreProcessingSteps(gitDirectory);
}
}
versionAndBranch = VersionCache.GetVersion(gitDirectory);
return true;
}
示例13: semantic_from_version
public void semantic_from_version()
{
var version = new Version("1.0.0.23");
var sem = new SemanticVersion(version);
var sem2 = new SemanticVersion("1.0.0");
Assert.Equal(sem2,sem);
}
示例14: TryResolvePartialName
private bool TryResolvePartialName(string name, SemanticVersion version, FrameworkName targetFramework, out string assemblyLocation)
{
foreach (var gacPath in GetGacSearchPaths(targetFramework))
{
var di = new DirectoryInfo(Path.Combine(gacPath, name));
if (!di.Exists)
{
continue;
}
foreach (var assemblyFile in di.EnumerateFiles("*.dll", SearchOption.AllDirectories))
{
if (!Path.GetFileNameWithoutExtension(assemblyFile.Name).Equals(name, StringComparison.OrdinalIgnoreCase))
{
continue;
}
SemanticVersion assemblyVersion = VersionUtility.GetAssemblyVersion(assemblyFile.FullName);
if (version == null || assemblyVersion == version)
{
assemblyLocation = assemblyFile.FullName;
return true;
}
}
}
assemblyLocation = null;
return false;
}
示例15: WillReturnConflictIfAPackageWithTheIdAndSemanticVersionAlreadyExists
public void WillReturnConflictIfAPackageWithTheIdAndSemanticVersionAlreadyExists()
{
var version = new SemanticVersion("1.0.42");
var nuGetPackage = new Mock<IPackage>();
nuGetPackage.Setup(x => x.Id).Returns("theId");
nuGetPackage.Setup(x => x.Version).Returns(version);
var user = new User();
var packageRegistration = new PackageRegistration
{
Packages = new List<Package> { new Package { Version = version.ToString() } },
Owners = new List<User> { user }
};
var packageSvc = new Mock<IPackageService>();
packageSvc.Setup(x => x.FindPackageRegistrationById(It.IsAny<string>())).Returns(packageRegistration);
var userSvc = new Mock<IUserService>();
userSvc.Setup(x => x.FindByApiKey(It.IsAny<Guid>())).Returns(user);
var controller = CreateController(userSvc: userSvc, packageSvc: packageSvc, packageFromInputStream: nuGetPackage.Object);
// Act
var result = controller.CreatePackagePut(Guid.NewGuid().ToString());
// Assert
Assert.IsType<HttpStatusCodeWithBodyResult>(result);
var statusCodeResult = (HttpStatusCodeWithBodyResult)result;
Assert.Equal(409, statusCodeResult.StatusCode);
Assert.Equal(String.Format(Strings.PackageExistsAndCannotBeModified, "theId", "1.0.42"), statusCodeResult.StatusDescription);
}