Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable GenerateAssemblyInfo and GenerateMSBuildEditorConfigFile #279

Merged
merged 2 commits into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
</ItemGroup>

<ItemGroup Condition="'$(IsTestProject)' == 'true'">
<Compile Include="$(MSBuildThisFileDirectory)src\Shared\MockTaskItem.cs" />
<Compile Include="$(MSBuildThisFileDirectory)src\Shared\MSBuildSdkTestBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)src\Shared\*.cs" />

<Content Include="$(MSBuildThisFileDirectory)xunit.runner.json"
CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion MSBuildSdks.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{DC479DC1
Directory.Build.rsp = Directory.Build.rsp
Directory.Build.targets = Directory.Build.targets
global.json = global.json
src\GlobalSuppressions.cs = src\GlobalSuppressions.cs
LICENSE.txt = LICENSE.txt
NuGet.config = NuGet.config
Packages.props = Packages.props
Expand Down
6 changes: 3 additions & 3 deletions Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageReference Update="Microsoft.Build.Utilities.Core" Version="$(MicrosoftBuildPackageVersion)" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Update="Microsoft.Win32.Registry" Version="4.7.0" />
<PackageReference Update="MSBuild.ProjectCreation" Version="4.0.1" />
<PackageReference Update="MSBuild.ProjectCreation" Version="4.0.4" />
<PackageReference Update="Shouldly" Version="4.0.3" />
<PackageReference Update="System.Security.Cryptography.ProtectedData" Version="4.7.0" />
<PackageReference Update="xunit" Version="2.4.1" />
Expand All @@ -23,7 +23,7 @@

<ItemGroup Condition=" '$(EnableStyleCop)' != 'false' ">
<GlobalPackageReference Include="StyleCop.Analyzers" Version="1.1.118" />
<Compile Include="..\GlobalSuppressions.cs" Visible="False" />
<AdditionalFiles Include="..\..\stylecop.json" Visible="False" />
<Compile Include="$(MSBuildThisFileDirectory)src\GlobalSuppressions.cs" />
<AdditionalFiles Include="$(MSBuildThisFileDirectory)stylecop.json" />
</ItemGroup>
</Project>
77 changes: 18 additions & 59 deletions src/NoTargets.UnitTests/NoTargetsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,65 +93,6 @@ public void DoNotReferenceOutputAssemblies()
result.ShouldBeTrue(buildOutput.GetConsoleLog());
}

[Fact]
public void EnableDefaultCompileItemsIsFalse()
{
ProjectCreator.Templates.NoTargetsProject(
path: GetTempFileWithExtension(".csproj"))
.Property("GenerateDependencyFile", "false")
.Save()
.TryGetPropertyValue("EnableDefaultCompileItems", out string enableDefaultCompileItems);

enableDefaultCompileItems.ShouldBe("false");
}

[Fact]
public void EnableDefaultEmbeddedResourceItemsIsFalse()
{
ProjectCreator.Templates.NoTargetsProject(
path: GetTempFileWithExtension(".csproj"))
.Property("GenerateDependencyFile", "false")
.Save()
.TryGetPropertyValue("EnableDefaultEmbeddedResourceItems", out string enableDefaultEmbeddedResourceItems);

enableDefaultEmbeddedResourceItems.ShouldBe("false");
}

[Fact]
public void ImplicitFrameworkReferencesDisabledByDefault()
{
ProjectCreator.Templates.NoTargetsProject(
path: Path.Combine(TestRootPath, "NoTargets", "NoTargets.csproj"),
targetFramework: "net45")
.Save()
.TryGetPropertyValue("DisableImplicitFrameworkReferences", out string disableImplicitFrameworkReferences);

disableImplicitFrameworkReferences.ShouldBe(bool.TrueString, StringCompareShould.IgnoreCase);
}

[Fact]
public void IncludeBuildOutputIsFalseByDefault()
{
ProjectCreator.Templates.NoTargetsProject(
path: GetTempFileWithExtension(".csproj"))
.Save()
.TryGetPropertyValue("IncludeBuildOutput", out string includeBuildOutput);

includeBuildOutput.ShouldBe("false");
}

[Fact]
public void ProduceReferenceAssemblyIsFalse()
{
ProjectCreator.Templates.NoTargetsProject(
path: GetTempFileWithExtension(".csproj"))
.Property("ProduceReferenceAssembly", "true")
.Save()
.TryGetPropertyValue("IncludeBuildOutput", out string produceReferenceAssembly);

produceReferenceAssembly.ShouldBe("false");
}

[Theory]
[InlineData(".csproj")]
[InlineData(".proj")]
Expand Down Expand Up @@ -217,6 +158,24 @@ public void ProjectsCanDependOnNoTargetsProjects()
result.ShouldBeTrue(buildOutput.GetConsoleLog());
}

[Theory]
[InlineData("DisableImplicitFrameworkReferences", "true")]
[InlineData("EnableDefaultCompileItems", "false")]
[InlineData("EnableDefaultEmbeddedResourceItems", "false")]
[InlineData("GenerateAssemblyInfo", "false")]
[InlineData("GenerateMSBuildEditorConfigFile", "false")]
[InlineData("IncludeBuildOutput", "false")]
[InlineData("ProduceReferenceAssembly", "false")]
public void PropertiesHaveExpectedValues(string propertyName, string expectedValue)
{
ProjectCreator.Templates.NoTargetsProject(
path: GetTempFileWithExtension(".csproj"))
.Save()
.TryGetPropertyValue(propertyName, out string actualValue);

actualValue.ShouldBe(expectedValue, StringComparer.OrdinalIgnoreCase, customMessage: $"Property {propertyName} should have a value of \"{expectedValue}\" but its value was \"{actualValue}\"");
}

[Theory]
[InlineData(".csproj")]
[InlineData(".proj")]
Expand Down
6 changes: 6 additions & 0 deletions src/NoTargets/Sdk/Sdk.props
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@

<!-- Don't generate a deps file -->
<GenerateDependencyFile Condition="'$(GenerateDependencyFile)' == ''">false</GenerateDependencyFile>

<!-- Don't generate assembly info -->
<GenerateAssemblyInfo Condition="'$(GenerateAssemblyInfo)' == ''">false</GenerateAssemblyInfo>

<!-- Don't generate editor config file -->
<GenerateMSBuildEditorConfigFile Condition="'$(GenerateMSBuildEditorConfigFile)' == ''">false</GenerateMSBuildEditorConfigFile>
</PropertyGroup>

<ItemDefinitionGroup Condition=" '$(NoTargetsDoNotReferenceOutputAssemblies)' != 'false' ">
Expand Down
2 changes: 1 addition & 1 deletion src/NoTargets/version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"inherit": true,
"version": "3.1"
"version": "3.2"
}
46 changes: 0 additions & 46 deletions src/Shared/MSBuildSdkTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,10 @@ namespace Microsoft.Build.UnitTests.Common
{
public abstract class MSBuildSdkTestBase : MSBuildTestBase, IDisposable
{
private static readonly string[] EnvironmentVariablesToRemove =
{
"MSBuildSdksPath",
"MSBuildExtensionsPath",
};

private readonly string _currentDirectoryBackup;
private readonly Dictionary<string, string> _environmentVariableBackup = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
private readonly string _testRootPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

public MSBuildSdkTestBase()
{
File.WriteAllText(
Path.Combine(TestRootPath, "global.json"),
@"{
""sdk"": {
""version"": ""5.0.100"",
""rollForward"": ""latestMinor""
},
}");

File.WriteAllText(
Path.Combine(TestRootPath, "NuGet.config"),
@"<?xml version=""1.0"" encoding=""utf-8""?>
Expand All @@ -44,18 +27,7 @@ public MSBuildSdkTestBase()
</packageSources>
</configuration>");

// Save the current directory to restore it later
_currentDirectoryBackup = Environment.CurrentDirectory;

Environment.CurrentDirectory = TestRootPath;

// Backup and remove environment variables
foreach (string environmentVariableName in EnvironmentVariablesToRemove)
{
_environmentVariableBackup[environmentVariableName] = Environment.GetEnvironmentVariable(environmentVariableName);

Environment.SetEnvironmentVariable(environmentVariableName, null);
}
}

public string TestRootPath
Expand Down Expand Up @@ -91,24 +63,6 @@ protected virtual void Dispose(bool disposing)
{
if (disposing)
{
// Restore environment variables
foreach (var environmentVariable in _environmentVariableBackup)
{
Environment.SetEnvironmentVariable(environmentVariable.Key, environmentVariable.Value);
}

if (Directory.Exists(_currentDirectoryBackup))
{
try
{
Environment.CurrentDirectory = _currentDirectoryBackup;
}
catch (Exception)
{
// Ignored
}
}

if (Directory.Exists(TestRootPath))
{
try
Expand Down