public void It_does_not_contain_apphost_exe(bool multiTarget) { var extension = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : ""; _targetFrameworkOrFrameworks = "netcoreapp3.0"; var nugetPackage = SetupNuGetPackage(multiTarget); using (var nupkgReader = new PackageArchiveReader(nugetPackage)) { IEnumerable <NuGet.Frameworks.NuGetFramework> supportedFrameworks = nupkgReader.GetSupportedFrameworks(); supportedFrameworks.Should().NotBeEmpty(); foreach (NuGet.Frameworks.NuGetFramework framework in supportedFrameworks) { var allItems = nupkgReader.GetToolItems().SelectMany(i => i.Items).ToList(); allItems.Should().NotContain($"tools/{framework.GetShortFolderName()}/any/consoledemo{extension}"); } } var getValuesCommand = new GetValuesCommand( Log, _testRoot, _targetFrameworkOrFrameworks, "RunCommand", GetValuesCommand.ValueType.Property); getValuesCommand.Execute(); string runCommandPath = getValuesCommand.GetValues().Single(); Path.GetExtension(runCommandPath) .Should().Be(extension); File.Exists(runCommandPath).Should() .BeTrue("run command should be apphost executable (for WinExe) to debug. But it will not be packed"); }
public void It_should_import_AutoImports_for_installed_workloads() { var testProject = new TestProject() { Name = "WorkloadTest", TargetFrameworks = "net5.0" }; var testAsset = _testAssetsManager.CreateTestProject(testProject); var expectedProperty = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "WinTestWorkloadAutoImportPropsImported" : "UnixTestWorkloadAutoImportPropsImported"; var getValuesCommand = new GetValuesCommand(testAsset, expectedProperty); getValuesCommand .WithEnvironmentVariable("MSBuildEnableWorkloadResolver", "true") .Execute() .Should() .Pass(); getValuesCommand .GetValues() .Should() .BeEquivalentTo("true"); }
public void It_restores_only_ridless_tfm() { var testAsset = _testAssetsManager .CopyTestAsset("HelloWorld") .WithSource(); var getValuesCommand = new GetValuesCommand(Log, testAsset.TestRoot, ToolsetInfo.CurrentTargetFramework, "TargetDefinitions", GetValuesCommand.ValueType.Item) { DependsOnTargets = "RunResolvePackageDependencies", Properties = { { "EmitLegacyAssetsFileItems", "true" } } }; getValuesCommand .Execute() .Should() .Pass(); // When RuntimeIdentifier is not specified, the assets file // should only contain one target with no RIDs var targetDefs = getValuesCommand.GetValues(); targetDefs.Count.Should().Be(1); targetDefs.Should().Contain(ToolsetInfo.CurrentTargetFramework); }
public void It_should_import_aliased_pack() { var testProject = new TestProject() { Name = "WorkloadTest", TargetFrameworks = "net5.0-workloadtestplatform" }; var testAsset = _testAssetsManager .CreateTestProject(testProject); var expectedProperty = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "UsingWinTestWorkloadPack" : "UsingUnixTestWorkloadPack"; var getValuesCommand = new GetValuesCommand(testAsset, expectedProperty); getValuesCommand .Execute() .Should() .Pass(); getValuesCommand .GetValues() .Should() .BeEquivalentTo("true"); }
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 getValuesCommand = new GetValuesCommand(Stage0MSBuild, testAsset.TestRoot, "net46", "PlatformTarget", GetValuesCommand.ValueType.Property); getValuesCommand .Execute($"/p:RuntimeIdentifier={runtimeIdentifier}") .Should() .Pass(); getValuesCommand .GetValues() .Should() .BeEquivalentTo(expectedPlatformTarget); }
public void It_imports_when_targeting_dotnet_3() { var targetFramework = "netcoreapp3.1"; TestProject testProject = new TestProject() { Name = "windowsDesktopSdk", IsSdkProject = true, TargetFrameworks = targetFramework }; testProject.AdditionalProperties["UseWPF"] = "true"; testProject.AdditionalProperties["TargetPlatformIdentifier"] = "Windows"; var testAsset = _testAssetsManager.CreateTestProject(testProject); var buildCommand = new BuildCommand(testAsset); buildCommand.Execute() .Should() .Pass(); var getValuesCommand = new GetValuesCommand(testAsset, "ImportWindowsDesktopTargets"); getValuesCommand.Execute() .Should() .Pass(); getValuesCommand.GetValues().ShouldBeEquivalentTo(new[] { "true" }); }
public void It_succeeds_if_windows_target_platform_version_does_not_have_trailing_zeros(bool setInTargetframework) { var testProject = new TestProject() { Name = "ValidWindowsVersion", IsSdkProject = true, TargetFrameworks = setInTargetframework ? "net5.0-windows10.0.18362" : "net5.0" }; if (!setInTargetframework) { testProject.AdditionalProperties["TargetPlatformIdentifier"] = "Windows"; testProject.AdditionalProperties["TargetPlatformVersion"] = "10.0.18362"; } var testAsset = _testAssetsManager.CreateTestProject(testProject); var buildCommand = new BuildCommand(testAsset); buildCommand.Execute() .Should() .Pass(); var getValuesCommand = new GetValuesCommand(testAsset, "TargetPlatformVersion"); getValuesCommand.Execute() .Should() .Pass(); getValuesCommand.GetValues().Should().BeEquivalentTo(new[] { "10.0.18362.0" }); }
public void WhenTargetingWindowsSupportedOSVersionPropertySetsTargetPlatformMinVersion() { TestProject testProject = SetUpProject("net6.0-windows10.0.19041"); testProject.AdditionalProperties["SupportedOSPlatformVersion"] = "10.0.18362.0"; var testAsset = _testAssetsManager.CreateTestProject(testProject); var runCommand = new DotnetCommand(Log, "run"); runCommand.WorkingDirectory = Path.Combine(testAsset.TestRoot, testProject.Name); runCommand.Execute() .Should() .Pass() .And.HaveStdOutContaining(TargetPlatformAttribute("Windows10.0.19041.0")) .And.HaveStdOutContaining(SupportedOSPlatformAttribute("Windows10.0.18362.0")); var getValuesCommand = new GetValuesCommand(testAsset, "TargetPlatformMinVersion"); getValuesCommand.Execute() .Should() .Pass(); getValuesCommand.GetValues() .Should() .BeEquivalentTo("10.0.18362.0"); }
public void PlatformTargetInferredCorrectly(string packageToReference, bool referencePlatformPackage, string expectedPlatform) { var testProject = new TestProject() { Name = "AutoRuntimeIdentifierTest", TargetFrameworks = "net472", IsExe = true }; var packageElements = packageToReference.Split('/'); string packageName = packageElements[0]; string packageVersion = packageElements[1]; testProject.PackageReferences.Add(new TestPackageReference(packageName, packageVersion)); if (referencePlatformPackage) { testProject.PackageReferences.Add(new TestPackageReference("Microsoft.NETCore.Platforms", "2.1.0")); } var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: packageName + "_" + referencePlatformPackage.ToString()); var buildCommand = new BuildCommand(testAsset); buildCommand.Execute() .Should() .Pass(); var getValueCommand = new GetValuesCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name), testProject.TargetFrameworks, "PlatformTarget"); getValueCommand.Execute().Should().Should(); getValueCommand.GetValues().Single().Should().Be(expectedPlatform); }
private List <string> GetValuesFromTestLibrary(string itemTypeOrPropertyName, Action <GetValuesCommand> setup = null, string[] msbuildArgs = null, GetValuesCommand.ValueType valueType = GetValuesCommand.ValueType.Item, [CallerMemberName] string callingMethod = "") { msbuildArgs = msbuildArgs ?? Array.Empty <string>(); string targetFramework = "netstandard1.5"; var testAsset = _testAssetsManager .CopyTestAsset("AppWithLibrary", callingMethod) .WithSource() .Restore(relativePath: "TestLibrary"); var libraryProjectDirectory = Path.Combine(testAsset.TestRoot, "TestLibrary"); var getValuesCommand = new GetValuesCommand(Stage0MSBuild, libraryProjectDirectory, targetFramework, itemTypeOrPropertyName, valueType); if (setup != null) { setup(getValuesCommand); } getValuesCommand .Execute(msbuildArgs) .Should() .Pass(); var itemValues = getValuesCommand.GetValues(); return(itemValues); }
public void It_restores_only_ridless_tfm() { // Disable this test when using full Framework MSBuild, until MSBuild is updated // to provide conditions in NuGet ImportBefore/ImportAfter props/targets // https://github.com/dotnet/sdk/issues/874 if (UsingFullFrameworkMSBuild) { return; } var testAsset = _testAssetsManager .CopyTestAsset("HelloWorld") .WithSource() .Restore(Log); var getValuesCommand = new GetValuesCommand(Log, testAsset.TestRoot, "netcoreapp1.1", "TargetDefinitions", GetValuesCommand.ValueType.Item); getValuesCommand .Execute() .Should() .Pass(); // When RuntimeIdentifier is not specified, the assets file // should only contain one target with no RIDs var targetDefs = getValuesCommand.GetValues(); targetDefs.Count.Should().Be(1); targetDefs.Should().Contain(".NETCoreApp,Version=v1.1"); }
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 getValuesCommand = new GetValuesCommand(Stage0MSBuild, testAsset.TestRoot, "net46", "PlatformTarget", GetValuesCommand.ValueType.Property); getValuesCommand .Execute($"/p:RuntimeIdentifier=win7-x86", "/p:PlatformTarget=x64") .Should() .Pass(); getValuesCommand .GetValues() .Should() .BeEquivalentTo("x64"); }
public void It_infers_WinExe_output_type(string targetFramework, string propName, string propValue, string expectedOutputType) { var testProject = new TestProject() { Name = "WinExeOutput", TargetFrameworks = targetFramework, IsSdkProject = true, IsExe = true, }; testProject.AdditionalProperties[propName] = propValue; var asset = _testAssetsManager.CreateTestProject(testProject); var getValuesCommand = new GetValuesCommand(asset, "OutputType"); getValuesCommand .Execute() .Should() .Pass(); var values = getValuesCommand.GetValues(); values.Count.Should().Be(1); values.First().Should().Be(expectedOutputType); }
public void RuntimePackWithLabelIsSelected() { var testProject = new TestProject() { TargetFrameworks = "net5.0", IsExe = true, RuntimeIdentifier = EnvironmentInfo.GetCompatibleRid() }; var testAsset = _testAssetsManager.CreateTestProject(testProject); var knownRuntimePack = CreateTestKnownRuntimePack(); AddItem(testAsset, knownRuntimePack); var frameworkReferenceUpdate = new XElement("FrameworkReference", new XAttribute("Update", "Microsoft.NETCore.App"), new XAttribute("RuntimePackLabels", "Mono")); AddItem(testAsset, frameworkReferenceUpdate); var getValuesCommand = new GetValuesCommand(testAsset, "RuntimePack", GetValuesCommand.ValueType.Item) { DependsOnTargets = "ProcessFrameworkReferences", ShouldRestore = false }; getValuesCommand .Execute() .Should() .Pass(); // StartsWith instead of exact match because current RID is likely to be more specific than the runtime pack RID getValuesCommand.GetValues().Should().Contain(rp => rp.StartsWith("Microsoft.NETCore.App.Runtime.Mono.")); }
public void It_does_not_include_source_revision_id_if_disabled() { TestProject testProject = new TestProject() { Name = "ProjectWithSourceRevisionId", IsSdkProject = true, TargetFrameworks = "netcoreapp2.0", }; var testAsset = _testAssetsManager.CreateTestProject(testProject) .WithProjectChanges((path, project) => { var ns = project.Root.Name.Namespace; project.Root.Add( new XElement(ns + "Target", new XAttribute("Name", "InitializeSourceControlInformation"), new XElement(ns + "PropertyGroup", new XElement("SourceRevisionId", "xyz")))); project.Root.Add( new XElement(ns + "PropertyGroup", new XElement("SourceControlInformationFeatureSupported", "true"), new XElement("IncludeSourceRevisionInInformationalVersion", "false"))); }); var command = new GetValuesCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name), testProject.TargetFrameworks, valueName: "InformationalVersion"); command.Execute().Should().Pass(); command.GetValues().ShouldBeEquivalentTo(new[] { "1.0.0" }); }
public void DesignTimePackageDependenciesAreResolved(string targetFramework) { var testProject = new TestProject() { Name = "DesignTimePackageDependencies", TargetFrameworks = targetFramework, IsSdkProject = true }; testProject.PackageReferences.Add(new TestPackageReference("Newtonsoft.Json", "12.0.2", privateAssets: "All")); testProject.PackageReferences.Add(new TestPackageReference("Humanizer", "2.6.2")); var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: targetFramework); var getValuesCommand = new GetValuesCommand(testAsset, "_PackageDependenciesDesignTime", GetValuesCommand.ValueType.Item); getValuesCommand.DependsOnTargets = "ResolvePackageDependenciesDesignTime"; getValuesCommand.Execute() .Should() .Pass(); getValuesCommand.GetValues() .Should() .BeEquivalentTo("Newtonsoft.Json/12.0.2", "Humanizer/2.6.2"); }
public void It_restores_only_ridless_tfm() { var testAsset = _testAssetsManager .CopyTestAsset("HelloWorld") .WithSource() .Restore(Log); var getValuesCommand = new GetValuesCommand(Log, testAsset.TestRoot, "netcoreapp1.1", "TargetDefinitions", GetValuesCommand.ValueType.Item) { DependsOnTargets = "RunResolvePackageDependencies", }; getValuesCommand .Execute() .Should() .Pass(); // When RuntimeIdentifier is not specified, the assets file // should only contain one target with no RIDs var targetDefs = getValuesCommand.GetValues(); targetDefs.Count.Should().Be(1); targetDefs.Should().Contain(".NETCoreApp,Version=v1.1"); }
private void TestFrameworkReferenceProfiles( IEnumerable <string> frameworkReferences, IEnumerable <string> expectedReferenceNames, IEnumerable <string> notExpectedReferenceNames, bool selfContained, [CallerMemberName] string callingMethod = "") { var testProject = new TestProject() { Name = "WindowsFormsFrameworkReference", TargetFrameworks = "netcoreapp3.0", IsSdkProject = true, IsExe = true }; testProject.FrameworkReferences.AddRange(frameworkReferences); if (selfContained) { testProject.RuntimeIdentifier = EnvironmentInfo.GetCompatibleRid(testProject.TargetFrameworks); } string identifier = selfContained ? "_selfcontained" : string.Empty; var testAsset = _testAssetsManager.CreateTestProject(testProject, callingMethod, identifier) .Restore(Log, testProject.Name); string projectFolder = Path.Combine(testAsset.TestRoot, testProject.Name); var buildCommand = new BuildCommand(Log, projectFolder); buildCommand .Execute() .Should() .Pass(); var getValuesCommand = new GetValuesCommand(Log, projectFolder, testProject.TargetFrameworks, "Reference", GetValuesCommand.ValueType.Item); getValuesCommand.Execute().Should().Pass(); var references = getValuesCommand.GetValues(); var referenceNames = references.Select(Path.GetFileNameWithoutExtension); referenceNames.Should().Contain(expectedReferenceNames); if (notExpectedReferenceNames.Any()) { referenceNames.Should().NotContain(notExpectedReferenceNames); } if (selfContained) { var outputDirectory = buildCommand.GetOutputDirectory(testProject.TargetFrameworks, runtimeIdentifier: testProject.RuntimeIdentifier); // The output directory should have the DLLs which are not referenced at compile time but are // still part of the shared framework. outputDirectory.Should().HaveFiles(expectedReferenceNames.Concat(notExpectedReferenceNames) .Select(n => n + ".dll")); } }
public void ItHasNoPackageReferences() { var testProject = new TestProject() { Name = "NoPackageReferences", TargetFrameworks = "netcoreapp3.0", IsSdkProject = true, IsExe = true }; var testAsset = _testAssetsManager.CreateTestProject(testProject, testProject.Name); string testDirectory = Path.Combine(testAsset.TestRoot, testProject.Name); var getPackageReferences = new GetValuesCommand( Log, testDirectory, testProject.TargetFrameworks, "PackageReference", GetValuesCommand.ValueType.Item); getPackageReferences.Execute().Should().Pass(); List <string> packageReferences = getPackageReferences.GetValues(); packageReferences .Should() .BeEmpty(); }
public void It_should_get_suggested_workload_by_GetRequiredWorkloads_target() { var mainProject = new TestProject() { Name = "MainProject", TargetFrameworks = "net6.0-android", IsSdkProject = true, IsExe = true }; var testAsset = _testAssetsManager .CreateTestProject(mainProject); var getValuesCommand = new GetValuesCommand(testAsset, "_ResolvedSuggestedWorkload", GetValuesCommand.ValueType.Item); getValuesCommand.DependsOnTargets = "_GetRequiredWorkloads"; getValuesCommand.ShouldRestore = false; getValuesCommand.Execute("/p:SkipResolvePackageAssets=true") .Should() .Pass(); getValuesCommand.GetValues() .Should() .BeEquivalentTo("android"); }
public void It_defines_target_platform_defaults_correctly(string targetFramework, string propertyName, bool defaultsDefined) { TestProject testProject = new TestProject() { Name = "TargetPlatformDefaults", IsSdkProject = true, TargetFrameworks = targetFramework }; if (!propertyName.Equals(string.Empty)) { testProject.AdditionalProperties[propertyName] = "true"; } var testAsset = _testAssetsManager.CreateTestProject(testProject); var getValuesCommand = new GetValuesCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name), targetFramework, "TargetPlatformIdentifier"); getValuesCommand .Execute() .Should() .Pass(); var values = getValuesCommand.GetValues(); if (defaultsDefined) { values.Count().Should().Be(1); values.FirstOrDefault().Should().Be("Windows"); } else { values.Count().Should().Be(0); } }
public void It_does_not_include_Windows_App_SDK_items_if_Windows_App_SDK_is_absent() { var testProject = new TestProject() { Name = "DontIncludeSourceFilesInNone", TargetFrameworks = "net6.0", IsExe = true, }; // Not setting the "EnableDefaultWindowsAppSdkContentItems" or "EnableDefaultWindowsAppSdkPRIResourceItems" properties! var testAsset = _testAssetsManager.CreateTestProject(testProject); var projectFolder = Path.Combine(testAsset.TestRoot, testProject.Name); File.WriteAllText(Path.Combine(projectFolder, "ResourcesResw.resw"), "<root/>"); List <string> imageFiles = new List <string> { "TestImage1.png", "TestImage2.bmp", "TestImage3.jpg", "TestImage4.dds", "TestImage5.tif", "TestImage6.tga", "TestImage7.gif" }; foreach (string fileName in imageFiles) { File.WriteAllText(Path.Combine(projectFolder, fileName), ""); } // Validate None items. var getNoneItemsCommand = new GetValuesCommand(Log, projectFolder, testProject.TargetFrameworks, "None", GetValuesCommand.ValueType.Item); getNoneItemsCommand.Execute() .Should() .Pass(); var getNoneItems = getNoneItemsCommand.GetValues(); List <string> expectedFiles = imageFiles; expectedFiles.Add("ResourcesResw.resw"); getNoneItems.ShouldBeEquivalentTo(expectedFiles.ToArray()); // Validate PRIResource items. var getPRIResourceItemsCommand = new GetValuesCommand(Log, projectFolder, testProject.TargetFrameworks, "PRIResource", GetValuesCommand.ValueType.Item); getPRIResourceItemsCommand.Execute() .Should() .Pass(); getPRIResourceItemsCommand.GetValues() .Should() .BeEmpty(); // Validate Content items. var getContentItemsCommand = new GetValuesCommand(Log, projectFolder, testProject.TargetFrameworks, "Content", GetValuesCommand.ValueType.Item); getContentItemsCommand.Execute() .Should() .Pass(); getContentItemsCommand.GetValues() .Should() .BeEmpty(); }
public void It_resolves_analyzers_correctly(string language, string testAssetName) { var asset = _testAssetsManager .CopyTestAsset(testAssetName, identifier: language) .WithSource() .WithProjectChanges(project => { var ns = project.Root.Name.Namespace; project.Root.Add( new XElement(ns + "ItemGroup", new XElement(ns + "PackageReference", new XAttribute("Include", "Microsoft.DependencyValidation.Analyzers"), new XAttribute("Version", "0.9.0")), new XElement(ns + "PackageReference", new XAttribute("Include", "Microsoft.CodeQuality.Analyzers"), new XAttribute("Version", "2.6.0")))); }); var command = new GetValuesCommand( Log, Path.Combine(asset.Path, "TestApp"), "netcoreapp1.1", "Analyzer", GetValuesCommand.ValueType.Item); command.Execute().Should().Pass(); var analyzers = command.GetValues(); switch (language) { case "C#": analyzers.Select(RelativeNuGetPath).Should().BeEquivalentTo( "microsoft.codeanalysis.analyzers/1.1.0/analyzers/dotnet/cs/Microsoft.CodeAnalysis.Analyzers.dll", "microsoft.codeanalysis.analyzers/1.1.0/analyzers/dotnet/cs/Microsoft.CodeAnalysis.CSharp.Analyzers.dll", "microsoft.codequality.analyzers/2.6.0/analyzers/dotnet/cs/Microsoft.CodeQuality.Analyzers.dll", "microsoft.codequality.analyzers/2.6.0/analyzers/dotnet/cs/Microsoft.CodeQuality.CSharp.Analyzers.dll", "microsoft.dependencyvalidation.analyzers/0.9.0/analyzers/dotnet/Microsoft.DependencyValidation.Analyzers.dll" ); break; case "VB": analyzers.Select(RelativeNuGetPath).Should().BeEquivalentTo( "microsoft.codeanalysis.analyzers/1.1.0/analyzers/dotnet/vb/Microsoft.CodeAnalysis.Analyzers.dll", "microsoft.codeanalysis.analyzers/1.1.0/analyzers/dotnet/vb/Microsoft.CodeAnalysis.VisualBasic.Analyzers.dll", "microsoft.codequality.analyzers/2.6.0/analyzers/dotnet/vb/Microsoft.CodeQuality.Analyzers.dll", "microsoft.codequality.analyzers/2.6.0/analyzers/dotnet/vb/Microsoft.CodeQuality.VisualBasic.Analyzers.dll", "microsoft.dependencyvalidation.analyzers/0.9.0/analyzers/dotnet/Microsoft.DependencyValidation.Analyzers.dll" ); break; case "F#": analyzers.Should().BeEmpty(); break; default: throw new ArgumentOutOfRangeException(nameof(language)); } }
public void It_resolves_analyzers_targeting_mulitple_roslyn_versions(string compilerApiVersion) { var testProject = new TestProject() { TargetFrameworks = "netstandard2.0" }; // Disable analyzers built in to the SDK so we can more easily test the ones coming from NuGet packages testProject.AdditionalProperties["EnableNETAnalyzers"] = "false"; testProject.ProjectChanges.Add(project => { var itemGroup = XElement.Parse(@" <ItemGroup> <PackageReference Include=""Library.ContainsAnalyzer"" Version=""1.0.0"" /> <PackageReference Include=""Library.ContainsAnalyzer2"" Version=""1.0.0"" /> </ItemGroup>"); project.Root.Add(itemGroup); }); var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: compilerApiVersion); NuGetConfigWriter.Write(testAsset.Path, TestContext.Current.TestPackages); var command = new GetValuesCommand(testAsset, "Analyzer", GetValuesCommand.ValueType.Item); // set the CompilerApiVersion through a command line property to override any value brought in by // the CodeAnalysis targets. command.Properties.Add("CompilerApiVersion", compilerApiVersion); command.Execute().Should().Pass(); var analyzers = command.GetValues(); switch (compilerApiVersion) { case "roslyn3.9": analyzers.Select(RelativeNuGetPath).Should().BeEquivalentTo( "library.containsanalyzer/1.0.0/analyzers/dotnet/roslyn3.9/cs/Library.ContainsAnalyzer.dll", "library.containsanalyzer2/1.0.0/analyzers/dotnet/roslyn3.8/cs/Library.ContainsAnalyzer2.dll" ); break; case "roslyn4.0": analyzers.Select(RelativeNuGetPath).Should().BeEquivalentTo( "library.containsanalyzer/1.0.0/analyzers/dotnet/roslyn4.0/cs/Library.ContainsAnalyzer.dll", "library.containsanalyzer2/1.0.0/analyzers/dotnet/roslyn3.10/cs/Library.ContainsAnalyzer2.dll" ); break; default: throw new ArgumentOutOfRangeException(nameof(compilerApiVersion)); } }
public void It_does_not_include_source_or_resx_files_in_None() { var testProject = new TestProject() { Name = "DontIncludeSourceFilesInNone", TargetFrameworks = "netcoreapp2.0", IsExe = true, IsSdkProject = true }; testProject.AdditionalProperties["EnableDefaultCompileItems"] = "false"; testProject.AdditionalProperties["EnableDefaultResourceItems"] = "false"; var testAsset = _testAssetsManager.CreateTestProject(testProject) .WithProjectChanges(project => { var ns = project.Root.Name.Namespace; XElement itemGroup = new XElement(ns + "ItemGroup"); project.Root.Add(itemGroup); itemGroup.Add(new XElement(ns + "Compile", new XAttribute("Include", testProject.Name + ".cs"))); }) .Restore(Log, testProject.Name); var projectFolder = Path.Combine(testAsset.TestRoot, testProject.Name); File.WriteAllText(Path.Combine(projectFolder, "ShouldBeIgnored.cs"), "!InvalidCSharp!"); File.WriteAllText(Path.Combine(projectFolder, "Resources.resx"), "<Resource/>"); var getCompileItemsCommand = new GetValuesCommand(Log, projectFolder, testProject.TargetFrameworks, "Compile", GetValuesCommand.ValueType.Item); getCompileItemsCommand.Execute() .Should() .Pass(); var compileItems = getCompileItemsCommand.GetValues(); RemoveGeneratedCompileItems(compileItems); compileItems.ShouldBeEquivalentTo(new[] { testProject.Name + ".cs" }); var getNoneItemsCommand = new GetValuesCommand(Log, projectFolder, testProject.TargetFrameworks, "None", GetValuesCommand.ValueType.Item); getNoneItemsCommand.Execute() .Should() .Pass(); getNoneItemsCommand.GetValues() .Should().BeEmpty(); var getResourceItemsCommand = new GetValuesCommand(Log, projectFolder, testProject.TargetFrameworks, "Resource", GetValuesCommand.ValueType.Item); getResourceItemsCommand.Execute() .Should() .Pass(); getResourceItemsCommand.GetValues() .Should().BeEmpty(); }
public void It_makes_RootNamespace_safe_when_project_name_has_spaces(string targetFramework) { var testProject = new TestProject() { Name = "Project Name With Spaces", TargetFrameworks = targetFramework, IsSdkProject = true }; var testAsset = _testAssetsManager.CreateTestProject(testProject); // Overwrite the default file. CreateTestProject uses the defined project name for the namespace. // We need a buildable project to extract the property to verify it // since this issue only surfaces in VS when adding a new class through an item template. File.WriteAllText(Path.Combine(testAsset.Path, testProject.Name, $"{testProject.Name}.cs"), @" using System; using System.Collections.Generic; namespace ProjectNameWithSpaces { public class ProjectNameWithSpacesClass { public static string Name { get { return ""Project Name With Spaces""; } } public static List<string> List { get { return null; } } } }"); string projectFolder = Path.Combine(testAsset.Path, testProject.Name); var buildCommand = new BuildCommand(testAsset, $"{ testProject.Name}"); buildCommand .Execute() .Should() .Pass(); string GetPropertyValue(string propertyName) { var getValuesCommand = new GetValuesCommand(Log, projectFolder, testProject.TargetFrameworks, propertyName, GetValuesCommand.ValueType.Property) { Configuration = "Debug" }; getValuesCommand .Execute() .Should() .Pass(); var values = getValuesCommand.GetValues(); values.Count.Should().Be(1); return(values[0]); } GetPropertyValue("RootNamespace").Should().Be("Project_Name_With_Spaces"); }
public void It_includes_Windows_App_SDK_items_in_the_correct_groups_if_Windows_App_SDK_is_present() { var testProject = new TestProject() { Name = "DontIncludeSourceFilesInNone", TargetFrameworks = "net6.0", IsExe = true, }; // Windows App SDK testProject.AdditionalProperties["EnableDefaultWindowsAppSdkContentItems"] = "true"; testProject.AdditionalProperties["EnableDefaultWindowsAppSdkPRIResourceItems"] = "true"; var testAsset = _testAssetsManager.CreateTestProject(testProject); var projectFolder = Path.Combine(testAsset.TestRoot, testProject.Name); File.WriteAllText(Path.Combine(projectFolder, "ResourcesResw.resw"), "<root/>"); string[] imageFiles = { "TestImage1.png", "TestImage2.bmp", "TestImage3.jpg", "TestImage4.dds", "TestImage5.tif", "TestImage6.tga", "TestImage7.gif" }; foreach (string fileName in imageFiles) { File.WriteAllText(Path.Combine(projectFolder, fileName), ""); } // Validate None items. var getNoneItemsCommand = new GetValuesCommand(Log, projectFolder, testProject.TargetFrameworks, "None", GetValuesCommand.ValueType.Item); getNoneItemsCommand.Execute() .Should() .Pass(); getNoneItemsCommand.GetValues() .Should() .BeEmpty(); // Validate PRIResource items. var getPRIResourceItemsCommand = new GetValuesCommand(Log, projectFolder, testProject.TargetFrameworks, "PRIResource", GetValuesCommand.ValueType.Item); getPRIResourceItemsCommand.Execute() .Should() .Pass(); var getPRIResourceItems = getPRIResourceItemsCommand.GetValues(); getPRIResourceItems.ShouldBeEquivalentTo(new[] { "ResourcesResw.resw" }); // Validate Content items. var getContentItemsCommand = new GetValuesCommand(Log, projectFolder, testProject.TargetFrameworks, "Content", GetValuesCommand.ValueType.Item); getContentItemsCommand.Execute() .Should() .Pass(); var getContentItems = getContentItemsCommand.GetValues(); getContentItems.ShouldBeEquivalentTo(imageFiles); }
private string GetPropertyValue(TestAsset testAsset, string propertyName) { var getValueCommand = new GetValuesCommand(testAsset, propertyName); getValueCommand.Execute() .Should() .Pass(); return(getValueCommand.GetValues().Single()); }
public void It_implicitly_defines_compilation_constants_for_the_target_framework(string targetFramework, string[] expectedDefines) { var testAsset = _testAssetsManager .CopyTestAsset("AppWithLibraryVB", "ImplicitFrameworkConstantsVB", targetFramework, identifier: targetFramework) .WithSource() .WithProjectChanges(project => { // Update target framework in project var ns = project.Root.Name.Namespace; var targetFrameworkProperties = project.Root .Elements(ns + "PropertyGroup") .Elements(ns + "TargetFramework") .ToList(); targetFrameworkProperties.Count.Should().Be(1); if (targetFramework.Contains(",Version=")) { var frameworkName = new FrameworkName(targetFramework); var targetFrameworkProperty = targetFrameworkProperties.Single(); targetFrameworkProperty.AddBeforeSelf(new XElement(ns + "TargetFrameworkIdentifier", frameworkName.Identifier)); targetFrameworkProperty.AddBeforeSelf(new XElement(ns + "TargetFrameworkVersion", "v" + frameworkName.Version.ToString())); if (!string.IsNullOrEmpty(frameworkName.Profile)) { targetFrameworkProperty.AddBeforeSelf(new XElement(ns + "TargetFrameworkProfile", frameworkName.Profile)); } // For the NuGet restore task to work with package references, it needs the TargetFramework property to be set. // Otherwise we would just remove the property. targetFrameworkProperty.SetValue(targetFramework); } else { targetFrameworkProperties.Single().SetValue(targetFramework); } }); var libraryProjectDirectory = Path.Combine(testAsset.TestRoot, "TestLibrary"); var getValuesCommand = new GetValuesCommand(Log, libraryProjectDirectory, targetFramework, "FinalDefineConstants") { DependsOnTargets = "AddImplicitDefineConstants" }; getValuesCommand .Execute() .Should() .Pass(); var definedConstants = ExpandSequence(getValuesCommand.GetValues()).ToList(); definedConstants.Should().BeEquivalentTo(new[] { "CONFIG=\"Debug\"", "DEBUG=-1", "TRACE=-1", "PLATFORM=\"AnyCPU\"" }.Concat(expectedDefines).ToArray()); }
private List <string> GetItems(string testDirectory, string tfm, string itemName) { var command = new GetValuesCommand( Log, testDirectory, tfm, itemName, GetValuesCommand.ValueType.Item); command.DependsOnTargets = ""; command.Execute().Should().Pass(); return(command.GetValues()); }