public void TestDiscoverEditorConfigFiles() { var srcFile = ProjectDir.CreateFile("lib1.cs").WriteAllText("class C { }"); var subdir = ProjectDir.CreateDirectory("subdir"); var srcFile2 = subdir.CreateFile("lib2.cs").WriteAllText("class D { }"); var editorConfigFile2 = subdir.CreateFile(".editorconfig").WriteAllText(@"[*.cs] some_prop = some_val"); VerifyValues( customProps: null, customTargets: null, targets: new[] { "CoreCompile" }, expressions: new[] { "@(EditorConfigFiles)" }, expectedResults: new[] { Path.Combine(ProjectDir.Path, ".editorconfig"), editorConfigFile2.Path }); }
public void TestGlobalConfigsCanBeManuallyAdded() { var srcFile = ProjectDir.CreateFile("lib1.cs").WriteAllText("class C { }"); var globalConfigFile = ProjectDir.CreateFile("mycustom.config").WriteAllText(@"is_global = true some_prop = some_val"); VerifyValues( customProps: @" <ItemGroup> <GlobalAnalyzerConfigFiles Include=""mycustom.config"" /> </ItemGroup>", customTargets: null, targets: new[] { "CoreCompile" }, expressions: new[] { "@(EditorConfigFiles)" }, expectedResults: AppendExtraEditorConfigs(new[] { Path.Combine(ProjectDir.Path, ".editorconfig"), "mycustom.config" })); }
public void TestDiscoverEditorAndGlobalConfigFilesCanBeDisabled() { var srcFile = ProjectDir.CreateFile("lib1.cs").WriteAllText("class C { }"); var globalConfigFile = ProjectDir.CreateFile(".globalconfig").WriteAllText(@"is_global = true some_prop = some_val"); var subdir = ProjectDir.CreateDirectory("subdir"); var globalConfigFile2 = subdir.CreateFile(".globalconfig").WriteAllText(@"is_global = true some_prop = some_val"); VerifyValues( customProps: @" <PropertyGroup> <DiscoverEditorConfigFiles>false</DiscoverEditorConfigFiles> <DiscoverGlobalAnalyzerConfigFiles>false</DiscoverGlobalAnalyzerConfigFiles> </PropertyGroup>", customTargets: null, targets: new[] { "CoreCompile" }, expressions: new[] { "@(EditorConfigFiles)" }, expectedResults: new[] { "" }); }
public void TestDiscoverGlobalConfigFilesWhenEditorConfigDisabled() { var srcFile = ProjectDir.CreateFile("lib1.cs").WriteAllText("class C { }"); var globalConfigFile = ProjectDir.CreateFile(".globalconfig").WriteAllText(@"is_global = true some_prop = some_val"); var subdir = ProjectDir.CreateDirectory("subdir"); var srcFile2 = subdir.CreateFile("lib2.cs").WriteAllText("class D { }"); var globalConfigFile2 = subdir.CreateFile(".globalconfig").WriteAllText(@"is_global = true some_prop = some_val"); VerifyValues( customProps: @" <PropertyGroup> <DiscoverEditorConfigFiles>false</DiscoverEditorConfigFiles> </PropertyGroup>", customTargets: null, targets: new[] { "CoreCompile" }, expressions: new[] { "@(EditorConfigFiles)" }, expectedResults: AppendExtraEditorConfigs(new[] { globalConfigFile.Path, globalConfigFile2.Path }, findEditorConfigs: false)); }
public void TestDiscoverGlobalConfigFilesCanBeDisabled() { var srcFile = ProjectDir.CreateFile("lib1.cs").WriteAllText("class C { }"); var globalConfigFile = ProjectDir.CreateFile(".globalconfig").WriteAllText(@"is_global = true some_prop = some_val"); var subdir = ProjectDir.CreateDirectory("subdir"); var srcFile2 = subdir.CreateFile("lib2.cs").WriteAllText("class D { }"); var globalConfigFile2 = subdir.CreateFile(".globalconfig").WriteAllText(@"is_global = true some_prop = some_val"); VerifyValues( customProps: @" <PropertyGroup> <DiscoverGlobalAnalyzerConfigFiles>false</DiscoverGlobalAnalyzerConfigFiles> <!-- Disable automatic global .editorconfig generation by the SDK --> <GenerateMSBuildEditorConfigFile>false</GenerateMSBuildEditorConfigFile> </PropertyGroup>", customTargets: null, targets: new[] { "CoreCompile" }, expressions: new[] { "@(EditorConfigFiles)" }, expectedResults: AppendExtraEditorConfigs(new[] { Path.Combine(ProjectDir.Path, ".editorconfig"), }, findGlobalConfigs: false)); }
public void InitializeSourceRootMappedPathsReturnsSourceMap(bool deterministicSourcePaths) { ProjectDir.CreateFile("Project2.csproj").WriteAllText($@" <Project Sdk='Microsoft.NET.Sdk'> <PropertyGroup> <TargetFramework>netstandard2.0</TargetFramework> <DeterministicSourcePaths>{deterministicSourcePaths}</DeterministicSourcePaths> </PropertyGroup> <ItemGroup> <SourceRoot Include=""X\""/> <SourceRoot Include=""Y\"" ContainingRoot=""X\"" NestedRoot=""A""/> <SourceRoot Include=""Z\"" ContainingRoot=""X\"" NestedRoot=""B""/> </ItemGroup> </Project> "); VerifyValues( customProps: $@" <ItemGroup> <ProjectReference Include=""Project2.csproj"" Targets=""InitializeSourceRootMappedPaths"" OutputItemType=""ReferencedProjectSourceRoots"" ReferenceOutputAssembly=""false"" /> </ItemGroup> ", customTargets: null, targets: new[] { "ResolveProjectReferences;_BeforeVBCSCoreCompile" }, expressions: new[] { "@(ReferencedProjectSourceRoots)", }, expectedResults: new[] { $"X{Path.DirectorySeparatorChar}", $"Y{Path.DirectorySeparatorChar}", $"Z{Path.DirectorySeparatorChar}", }); }