public void It_chooses_lowest_netfx_in_default_atf() { var testProjectName = "netcoreapp30_multiple_atf"; var(testProjectTestAsset, testPackageReference) = CreateTestAsset( testProjectName, "netcoreapp3.0", "net462;net472", new Dictionary <string, string> { ["CopyLocalLockFileAssemblies"] = "true" }); var source = Path.Combine(testPackageReference.NupkgPath, testPackageReference.ID, "bin", "Debug"); NuGetConfigWriter.Write(testProjectTestAsset.TestRoot, source); var restoreCommand = testProjectTestAsset.GetRestoreCommand(Log, relativePath: testProjectName); restoreCommand.Execute().Should().Pass(); var buildCommand = new BuildCommand(testProjectTestAsset); buildCommand.Execute().Should().Pass(); var referencedDll = buildCommand.GetOutputDirectory("netcoreapp3.0").File("net462_net472_pkg.dll").FullName; var referencedTargetFramework = AssemblyInfo.Get(referencedDll)["TargetFrameworkAttribute"]; referencedTargetFramework.Should().Be(".NETFramework,Version=v4.6.2"); }
public void It_respects_version_prefix(string targetFramework) { if (targetFramework == "net45" && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { return; } var testAsset = _testAssetsManager .CopyTestAsset("HelloWorld", identifier: targetFramework) .WithSource() .Restore(Log, "", $"/p:OutputType=Library;TargetFramework={targetFramework}"); var buildCommand = new BuildCommand(Log, testAsset.TestRoot); buildCommand .Execute($"/p:OutputType=Library;TargetFramework={targetFramework};VersionPrefix=1.2.3") .Should() .Pass(); var assemblyPath = Path.Combine(buildCommand.GetOutputDirectory(targetFramework).FullName, "HelloWorld.dll"); var info = AssemblyInfo.Get(assemblyPath); info["AssemblyVersionAttribute"].Should().Be("1.2.3.0"); info["AssemblyFileVersionAttribute"].Should().Be("1.2.3.0"); info["AssemblyInformationalVersionAttribute"].Should().Be("1.2.3"); }
public void It_respects_version_changes_on_incremental_build(string targetFramework) { if (targetFramework == "net45" && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { return; } // Given a project that has already been built var testAsset = _testAssetsManager .CopyTestAsset("HelloWorld", identifier: targetFramework) .WithSource() .Restore(Log, "", $"/p:OutputType=Library;TargetFramework={targetFramework}"); BuildProject(versionPrefix: "1.2.3"); // When the same project is built again using a different VersionPrefix proeprty var incrementalBuildCommand = BuildProject(versionPrefix: "1.2.4"); // Then the version of the built assembly shall match the provided VersionPrefix var assemblyPath = Path.Combine(incrementalBuildCommand.GetOutputDirectory(targetFramework).FullName, "HelloWorld.dll"); var info = AssemblyInfo.Get(assemblyPath); info["AssemblyVersionAttribute"].Should().Be("1.2.4.0"); BuildCommand BuildProject(string versionPrefix) { var command = new BuildCommand(Log, testAsset.TestRoot); command.Execute($"/p:OutputType=Library;TargetFramework={targetFramework};VersionPrefix={versionPrefix}") .Should() .Pass(); return(command); } }
public void It_builds_with_inferred_platform_target(string runtimeIdentifier, string expectedPlatformTarget) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { return; } var testAsset = _testAssetsManager .CopyTestAsset("DesktopMinusRid", identifier: Path.DirectorySeparatorChar + runtimeIdentifier) .WithSource() .Restore("", $"/p:RuntimeIdentifier={runtimeIdentifier}"); var buildCommand = new BuildCommand(Stage0MSBuild, testAsset.TestRoot); buildCommand .Execute($"/p:RuntimeIdentifier={runtimeIdentifier}") .Should() .Pass(); var assemblyPath = Path.Combine(buildCommand.GetOutputDirectory("net46").FullName, "DesktopMinusRid.exe"); var assemblyInfo = AssemblyInfo.Get(assemblyPath); assemblyInfo .Should() .Contain( "AssemblyDescriptionAttribute", $"PlatformTarget={expectedPlatformTarget}"); }
public void It_respects_explicit_platform_target() { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { return; } var testAsset = _testAssetsManager .CopyTestAsset("DesktopMinusRid") .WithSource() .Restore("", $"/p:RuntimeIdentifier=win7-x86"); var buildCommand = new BuildCommand(Stage0MSBuild, testAsset.TestRoot); buildCommand .Execute($"/p:RuntimeIdentifier=win7-x86", "/p:PlatformTarget=x64") .Should() .Pass(); var assemblyPath = Path.Combine(buildCommand.GetOutputDirectory("net46").FullName, "DesktopMinusRid.exe"); var assemblyInfo = AssemblyInfo.Get(assemblyPath); assemblyInfo .Should() .Contain( "AssemblyDescriptionAttribute", $"PlatformTarget=x64"); }
public void It_includes_repository_url(bool privateRepo) { var fakeUrl = "fakeUrl"; var testProject = new TestProject() { Name = "RepoUrlProject", TargetFrameworks = "netcoreapp3.1" }; if (privateRepo) { testProject.AdditionalProperties["PublishRepositoryUrl"] = "true"; testProject.AdditionalProperties["PrivateRepositoryUrl"] = fakeUrl; } else { testProject.AdditionalProperties["RepositoryUrl"] = fakeUrl; } var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: privateRepo.ToString()); var buildCommand = new BuildCommand(testAsset); buildCommand.Execute().Should().Pass(); var assemblyPath = Path.Combine(buildCommand.GetOutputDirectory("netcoreapp3.1").FullName, testProject.Name + ".dll"); AssemblyInfo.Get(assemblyPath)["AssemblyMetadataAttribute"].Should().Be("RepositoryUrl:" + fakeUrl); }
public void It_does_not_write_to_undefined_assembly_metadata_attribute(string targetFramework, bool containsAttribute) { var fakeUrl = "fakeUrl"; var testProject = new TestProject() { Name = "RepoUrlProject", TargetFrameworks = targetFramework }; testProject.AdditionalProperties["RepositoryUrl"] = fakeUrl; var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: targetFramework); var buildCommand = new BuildCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); buildCommand.Execute() .Should() .Pass(); var assemblyPath = Path.Combine(buildCommand.GetOutputDirectory(targetFramework).FullName, testProject.Name + ".dll"); if (containsAttribute) { AssemblyInfo.Get(assemblyPath)["AssemblyMetadataAttribute"].Should().Be("RepositoryUrl:" + fakeUrl); } else { AssemblyInfo.Get(assemblyPath).ContainsKey("AssemblyMetadataAttribute").Should().Be(false); } }
public void It_includes_internals_visible_to_with_project_publickey() { var testAsset = _testAssetsManager .CopyTestAsset("HelloWorld") .WithSource() .WithTargetFramework("netstandard2.0") .WithProjectChanges((path, project) => { var ns = project.Root.Name.Namespace; project.Root.Add( new XElement(ns + "PropertyGroup", new XElement(ns + "PublicKey", "00240000048000009400000006020000002400005253413100040000010001001d3e6bbb36e11ea61ceff6e1022b23dd779fc6230838db2d25a2c7c8433b3fcf86b16c25b281fc3db1027c0675395e7d0548e6add88b6a811962bf958101fa9e243b1618313bee11f5e3b3fefda7b1d1226311b6cc2d07e87ff893ba6890b20082df34a0aac14b605b8be055e81081a626f8c69e9ed4bbaa4eae9f94a35accd2")), new XElement(ns + "ItemGroup", new XElement(ns + "InternalsVisibleTo", new XAttribute("Include", "Tests")))); }); var buildCommand = new BuildCommand(testAsset); buildCommand.Execute().Should().Pass(); var assemblyPath = Path.Combine(buildCommand.GetOutputDirectory("netstandard2.0").FullName, "HelloWorld.dll"); AssemblyInfo.Get(assemblyPath)["InternalsVisibleToAttribute"].Should().Be("Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001001d3e6bbb36e11ea61ceff6e1022b23dd779fc6230838db2d25a2c7c8433b3fcf86b16c25b281fc3db1027c0675395e7d0548e6add88b6a811962bf958101fa9e243b1618313bee11f5e3b3fefda7b1d1226311b6cc2d07e87ff893ba6890b20082df34a0aac14b605b8be055e81081a626f8c69e9ed4bbaa4eae9f94a35accd2"); }
public void It_respects_out_out_of_assembly_metadata() { var testAsset = _testAssetsManager .CopyTestAsset("HelloWorld") .WithSource() .WithTargetFramework("netstandard2.0") .WithProjectChanges((path, project) => { var ns = project.Root.Name.Namespace; project.Root.Add( new XElement(ns + "PropertyGroup", new XElement(ns + "GenerateAssemblyMetadataAttributes", "false")), new XElement(ns + "ItemGroup", new XElement(ns + "AssemblyMetadata", new XAttribute("Include", "MetadataKey"), new XAttribute("Value", "MetadataValue")))); }); var buildCommand = new BuildCommand(testAsset); buildCommand.Execute().Should().Pass(); var assemblyPath = Path.Combine(buildCommand.GetOutputDirectory("netstandard2.0").FullName, "HelloWorld.dll"); Assert.False(AssemblyInfo.Get(assemblyPath).ContainsKey("AssemblyMetadataAttribute")); }
public void It_includes_assembly_metadata() { var testAsset = _testAssetsManager .CopyTestAsset("HelloWorld") .WithSource() .WithTargetFramework("netstandard2.0") .WithProjectChanges((path, project) => { var ns = project.Root.Name.Namespace; project.Root.Add( new XElement(ns + "ItemGroup", new XElement(ns + "AssemblyMetadata", new XAttribute("Include", "MetadataKey"), new XAttribute("Value", "MetadataValue")))); }); var buildCommand = new BuildCommand(Log, testAsset.TestRoot); buildCommand.Execute().Should().Pass(); var assemblyPath = Path.Combine(buildCommand.GetOutputDirectory("netstandard2.0").FullName, "HelloWorld.dll"); AssemblyInfo.Get(assemblyPath)["AssemblyMetadataAttribute"].Should().Be("MetadataKey:MetadataValue"); }
public void It_respects_opt_outs(string attributeToOptOut) { var testAsset = _testAssetsManager .CopyTestAsset("HelloWorld", identifier: Path.DirectorySeparatorChar + attributeToOptOut) .WithSource() .Restore(Log); var buildCommand = new BuildCommand(Log, testAsset.TestRoot); buildCommand .Execute( "/p:Version=1.2.3-beta", "/p:FileVersion=4.5.6.7", "/p:AssemblyVersion=8.9.10.11", "/p:Company=TestCompany", "/p:Configuration=Release", "/p:Copyright=TestCopyright", "/p:Description=TestDescription", "/p:Product=TestProduct", "/p:AssemblyTitle=TestTitle", "/p:NeutralLanguage=fr", attributeToOptOut == "All" ? "/p:GenerateAssemblyInfo=false" : $"/p:Generate{attributeToOptOut}=false" ) .Should() .Pass(); var expectedInfo = new SortedDictionary <string, string> { { "AssemblyInformationalVersionAttribute", "1.2.3-beta" }, { "AssemblyFileVersionAttribute", "4.5.6.7" }, { "AssemblyVersionAttribute", "8.9.10.11" }, { "AssemblyCompanyAttribute", "TestCompany" }, { "AssemblyConfigurationAttribute", "Release" }, { "AssemblyCopyrightAttribute", "TestCopyright" }, { "AssemblyDescriptionAttribute", "TestDescription" }, { "AssemblyProductAttribute", "TestProduct" }, { "AssemblyTitleAttribute", "TestTitle" }, { "NeutralResourcesLanguageAttribute", "fr" }, }; if (attributeToOptOut == "All") { expectedInfo.Clear(); } else { expectedInfo.Remove(attributeToOptOut); } expectedInfo.Add("TargetFrameworkAttribute", ".NETCoreApp,Version=v1.1"); var assemblyPath = Path.Combine(buildCommand.GetOutputDirectory("netcoreapp1.1", "Release").FullName, "HelloWorld.dll"); var actualInfo = AssemblyInfo.Get(assemblyPath); actualInfo.Should().Equal(expectedInfo); }
public void Build_AddsApplicationPartAttributes() { var testAsset = "RazorSimpleMvc"; var projectDirectory = CreateAspNetSdkTestAsset(testAsset); var build = new BuildCommand(projectDirectory); build.Execute().Should().Pass(); var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString(); var assemblyPath = Path.Combine(intermediateOutputPath, "SimpleMvc.dll"); AssemblyInfo.Get(assemblyPath)["AssemblyTitleAttribute"].Should().Be("SimpleMvc"); AssemblyInfo.Get(assemblyPath)["ProvideApplicationPartFactoryAttribute"].Should().Contain("ConsolidatedAssemblyApplicationPartFactory"); }
public void It_respects_custom_assembly_attribute_items_on_incremental_build() { var targetFramework = "netstandard1.5"; var testAsset = _testAssetsManager .CopyTestAsset("KitchenSink", identifier: targetFramework) .WithSource() .Restore(Log, "TestLibrary"); var firstBuildCommand = BuildProject(buildNumber: "1"); var assemblyPath = Path.Combine(firstBuildCommand.GetOutputDirectory(targetFramework).FullName, "TestLibrary.dll"); AssemblyInfo.Get(assemblyPath)["AssemblyMetadataAttribute"].Should().Be("BuildNumber:1"); var firstWriteTime = File.GetLastWriteTimeUtc(assemblyPath); // When rebuilding with the same value BuildProject(buildNumber: "1"); // the build should no-op. File.GetLastWriteTimeUtc(assemblyPath).Should().Be(firstWriteTime); // When the same project is built again using a different build number BuildProject(buildNumber: "2"); // the file should change File.GetLastWriteTimeUtc(assemblyPath).Should().NotBe(firstWriteTime); // and the custom assembly should be generated with the updated value. AssemblyInfo.Get(assemblyPath)["AssemblyMetadataAttribute"].Should().Be("BuildNumber:2"); BuildCommand BuildProject(string buildNumber) { var command = new BuildCommand(Log, Path.Combine(testAsset.TestRoot, "TestLibrary")); command.Execute($"/p:BuildNumber={buildNumber}") .Should() .Pass(); return(command); } }
public void GenerateUserSecretsForTestProject() { // Test the scenario where a test project references a web app and uses user secrets. var testProject = new TestProject() { Name = "WebApp", IsSdkProject = true, TargetFrameworks = "netcoreapp3.0" }; testProject.FrameworkReferences.Add("Microsoft.AspNetCore.App"); var testTestProject = new TestProject() { Name = "WebAppTests", IsSdkProject = true, TargetFrameworks = "netcoreapp3.0", ReferencedProjects = { testProject } }; var testAsset = _testAssetsManager.CreateTestProject(testTestProject); File.WriteAllText(Path.Combine(testAsset.TestRoot, "Directory.Build.props"), @" <Project> <PropertyGroup> <UserSecretsId>SecretsIdValue</UserSecretsId> </PropertyGroup> </Project> "); var buildCommand = new BuildCommand(Log, testAsset.TestRoot, testTestProject.Name); buildCommand.Execute("/restore") .Should() .Pass(); var assemblyPath = Path.Combine(buildCommand.GetOutputDirectory(testTestProject.TargetFrameworks).FullName, testTestProject.Name + ".dll"); AssemblyInfo.Get(assemblyPath)["UserSecretsIdAttribute"].Should().Be("SecretsIdValue"); }
public void GenerateUserSecrets(bool referenceAspNetCore, bool referenceExtensionsUserSecrets, bool shouldHaveAttribute) { var testProject = new TestProject() { Name = "UserSecretTest", IsSdkProject = true, TargetFrameworks = "netcoreapp3.0" }; testProject.AdditionalProperties["UserSecretsId"] = "SecretsIdValue"; if (referenceAspNetCore) { testProject.FrameworkReferences.Add("Microsoft.AspNetCore.App"); } if (referenceExtensionsUserSecrets) { testProject.PackageReferences.Add(new TestPackageReference("Microsoft.Extensions.Configuration.UserSecrets", "3.0.0")); } var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: referenceAspNetCore.ToString() + referenceExtensionsUserSecrets.ToString()) .Restore(Log, testProject.Name); var buildCommand = new BuildCommand(Log, testAsset.TestRoot, testProject.Name); buildCommand.Execute() .Should() .Pass(); var assemblyPath = Path.Combine(buildCommand.GetOutputDirectory(testProject.TargetFrameworks).FullName, testProject.Name + ".dll"); if (shouldHaveAttribute) { AssemblyInfo.Get(assemblyPath)["UserSecretsIdAttribute"].Should().Be("SecretsIdValue"); } else { AssemblyInfo.Get(assemblyPath).Should().NotContainKey("SecretsIdValue"); } }
public void It_includes_internals_visible_to() { var testAsset = _testAssetsManager .CopyTestAsset("HelloWorld") .WithSource() .WithTargetFramework("netstandard2.0") .WithProjectChanges((path, project) => { var ns = project.Root.Name.Namespace; project.Root.Add( new XElement(ns + "ItemGroup", new XElement(ns + "InternalsVisibleTo", new XAttribute("Include", "Tests")))); }); var buildCommand = new BuildCommand(testAsset); buildCommand.Execute().Should().Pass(); var assemblyPath = Path.Combine(buildCommand.GetOutputDirectory("netstandard2.0").FullName, "HelloWorld.dll"); AssemblyInfo.Get(assemblyPath)["InternalsVisibleToAttribute"].Should().Be("Tests"); }