Skip to content

Commit

Permalink
Adding RepositoryUrl to generated AssemblyInfo.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
sfoslund committed May 4, 2020
1 parent 27aa5ad commit d0b28b3
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ Copyright (c) .NET Foundation. All rights reserved.
<AssemblyAttribute Include="System.Reflection.AssemblyVersionAttribute" Condition="'$(AssemblyVersion)' != '' and '$(GenerateAssemblyVersionAttribute)' == 'true'">
<_Parameter1>$(AssemblyVersion)</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition="'$(RepositoryUrl)' != '' or '$(PublishRepositoryUrl)' == 'true'" >
<_Parameter1>RepositoryUrl</_Parameter1>
<_Parameter2 Condition="'$(RepositoryUrl)' != ''">$(RepositoryUrl)</_Parameter2>
<_Parameter2 Condition="'$(RepositoryUrl)' == ''">$(PrivateRepositoryUrl)</_Parameter2>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Resources.NeutralResourcesLanguageAttribute" Condition="'$(NeutralLanguage)' != '' and '$(GenerateNeutralResourcesLanguageAttribute)' == 'true'">
<_Parameter1>$(NeutralLanguage)</_Parameter1>
</AssemblyAttribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -595,5 +595,52 @@ public void GenerateUserSecretsForTestProject()

AssemblyInfo.Get(assemblyPath)["UserSecretsIdAttribute"].Should().Be("SecretsIdValue");
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void It_includes_repository_url(bool privateRepo)
{
var fakeUrl = "fakeUrl";
var testAsset = _testAssetsManager
.CopyTestAsset("HelloWorld")
.WithSource()
.WithTargetFramework("netcoreapp3.1");
if (privateRepo)
{
testAsset = testAsset
.WithProjectChanges((path, project) =>
{
var ns = project.Root.Name.Namespace;
project.Root.Add(
new XElement(ns + "PropertyGroup",
new XElement(ns + "PublishRepositoryUrl", true)));
project.Root.Add(
new XElement(ns + "PropertyGroup",
new XElement(ns + "PrivateRepositoryUrl", fakeUrl)));
});
}
else
{
testAsset = testAsset
.WithProjectChanges((path, project) =>
{
var ns = project.Root.Name.Namespace;
project.Root.Add(
new XElement(ns + "PropertyGroup",
new XElement(ns + "RepositoryUrl", fakeUrl)));
});
}


var buildCommand = new BuildCommand(Log, testAsset.TestRoot);
buildCommand.Execute().Should().Pass();

var assemblyPath = Path.Combine(buildCommand.GetOutputDirectory("netcoreapp3.1").FullName, "HelloWorld.dll");

AssemblyInfo.Get(assemblyPath)["AssemblyMetadataAttribute"].Should().Be("RepositoryUrl:" + fakeUrl);
}
}
}

0 comments on commit d0b28b3

Please sign in to comment.