Skip to content

Commit

Permalink
added conditions based on langVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
vlada-shubina committed Jul 13, 2021
1 parent 7c97b77 commit 4a16adf
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
<OutputType>Exe</OutputType>
<TargetFramework Condition="'$(TargetFrameworkOverride)' == ''">net6.0</TargetFramework>
<TargetFramework Condition="'$(TargetFrameworkOverride)' != ''">TargetFrameworkOverride</TargetFramework>
<RootNamespace Condition="'$(name)' != '$(name{-VALUE-FORMS-}safe_namespace)'">Company.ConsoleApplication1</RootNamespace>
<LangVersion Condition="'$(langVersion)' != ''">$(ProjectLanguageVersion)</LangVersion>
<Nullable>enable</Nullable>
<Nullable Condition="('$(langVersion)' == '' OR '$(langVersion)' == '8.0' OR '$(langVersion)' == '9.0' OR '$(langVersion)' == '10.0')">enable</Nullable>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
//We've made changes to the Console template! Find out more at https://aka.ms/new-console-template
// We've made changes to the Console template! Find out more at https://aka.ms/new-console-template

#if (langVersion != "" && langVersion != "10.0")
using System;

#endif
#if (langVersion != "" && langVersion != "10.0" && langVersion != "9.0")
namespace Console.ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}
}
#else
Console.WriteLine("Hello, World!");
#endif
18 changes: 17 additions & 1 deletion test/dotnet-new3.UnitTests/CommonTemplatesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ public CommonTemplatesTests(SharedHomeDirectory fixture, ITestOutputHelper log)
[InlineData("Class Library", "classlib", "C#", "net6.0", "7.2")]
[InlineData("Class Library", "classlib", "C#", "net6.0", "7.1")]
[InlineData("Class Library", "classlib", "C#", "net6.0", "7")]

[InlineData("Console Application", "console", "C#", "net6.0", "10.0")]
[InlineData("Console Application", "console", "C#", "net6.0", "9.0")]
[InlineData("Console Application", "console", "C#", "net6.0", "8.0")]
[InlineData("Console Application", "console", "C#", "net6.0", "7.3")]
[InlineData("Console Application", "console", "C#", "net6.0", "7.2")]
[InlineData("Console Application", "console", "C#", "net6.0", "7.1")]
[InlineData("Console Application", "console", "C#", "net6.0", "7")]
public void AllCommonProjectsCreateRestoreAndBuild(string expectedTemplateName, string templateShortName, string? language = null, string? framework = null, string? langVersion = null)
{
string workingDir = TestUtils.CreateTemporaryFolder();
Expand Down Expand Up @@ -243,6 +251,9 @@ public void AllCommonItemsCreate(string expectedTemplateName, string templateSho
[InlineData("Nullable", null, "Console Application", "console", null, "net5.0")]
[InlineData("Nullable", null, "Console Application", "console", null, "netcoreapp3.1")]
[InlineData("Nullable", null, "Console Application", "console", null, "netcoreapp2.1")]
[InlineData("Nullable", "enable", "Console Application", "console", null, null, "9.0")]
[InlineData("Nullable", "enable", "Console Application", "console", null, null, "8.0")]
[InlineData("Nullable", "enable", "Console Application", "console", null, null, "7.3")]

[InlineData("Nullable", null, "Console Application", "console", "F#", null)]
[InlineData("CheckForOverflowUnderflow", null, "Console Application", "console", "F#", null)]
Expand Down Expand Up @@ -275,7 +286,7 @@ public void AllCommonItemsCreate(string expectedTemplateName, string templateSho
[InlineData("TargetFramework", "net6.0", "Class Library", "classlib", "VB", null)]
[InlineData("Nullable", null, "Class Library", "classlib", "VB", "netstandard2.0")]

public void SetPropertiesByDefault(string propertyName, string? propertyValue, string expectedTemplateName, string templateShortName, string? language, string? framework)
public void SetPropertiesByDefault(string propertyName, string? propertyValue, string expectedTemplateName, string templateShortName, string? language, string? framework, string? langVersion = null)
{
string workingDir = TestUtils.CreateTemporaryFolder();
List<string> args = new List<string>() { templateShortName, "--no-restore" };
Expand All @@ -289,6 +300,11 @@ public void SetPropertiesByDefault(string propertyName, string? propertyValue, s
args.Add("--framework");
args.Add(framework);
}
if (!string.IsNullOrWhiteSpace(langVersion))
{
args.Add("--langVersion");
args.Add(langVersion);
}

new DotnetNewCommand(_log, args.ToArray())
.WithCustomHive(_fixture.HomeDirectory)
Expand Down

0 comments on commit 4a16adf

Please sign in to comment.