Skip to content

Commit

Permalink
Use 'Nullable' for Csc Task property (#35516)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcouv authored May 6, 2019
1 parent f1eeed9 commit 2d52a58
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
6 changes: 4 additions & 2 deletions docs/features/nullable-reference-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ Project level nullable context can be set by using "nullable" command line switc
-nullable[+|-] Specify nullable context option enable|disable.
-nullable:{enable|disable|safeonly|warnings|safeonlywarnings} Specify nullable context option enable|disable|safeonly|warnings|safeonlywarnings.

Through msbuild the context could be set by supplying an argument for a "NullableContextOptions" parameter of Csc build task.
Through msbuild the context could be set by supplying an argument for a "Nullable" parameter of Csc build task.
Accepted values are "enable", "disable", "safeonly", "warnings", "safeonlywarnings", or null (for the default nullable context according to the compiler).
The Microsoft.CSharp.Core.targets passes value of msbuild property named "NullableContextOptions" for that parameter.
The Microsoft.CSharp.Core.targets passes value of msbuild property named "Nullable" for that parameter.

Note that in previous preview releases of C# 8.0 this "Nullable" property was successively named "NullableReferenceTypes" then "NullableContextOptions".

## Annotations
In source, nullable reference types are annotated with `?`.
Expand Down
8 changes: 4 additions & 4 deletions src/Compilers/Core/MSBuildTask/Csc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ public string WarningsNotAsErrors
get { return (string)_store[nameof(WarningsNotAsErrors)]; }
}

public string NullableContextOptions
public string Nullable
{
set { _store[nameof(NullableContextOptions)] = value; }
get { return (string)_store[nameof(NullableContextOptions)]; }
set { _store[nameof(Nullable)] = value; }
get { return (string)_store[nameof(Nullable)]; }
}

#endregion
Expand Down Expand Up @@ -210,7 +210,7 @@ protected internal override void AddResponseFileCommands(CommandLineBuilderExten
commandLine.AppendWhenTrue("/errorendlocation", _store, nameof(ErrorEndLocation));
commandLine.AppendSwitchIfNotNull("/preferreduilang:", PreferredUILang);
commandLine.AppendPlusOrMinusSwitch("/highentropyva", _store, nameof(HighEntropyVA));
commandLine.AppendSwitchIfNotNull("/nullable:", NullableContextOptions);
commandLine.AppendSwitchIfNotNull("/nullable:", Nullable);
commandLine.AppendWhenTrue("/nosdkpath", _store, nameof(DisableSdkPath));

// If not design time build and the globalSessionGuid property was set then add a -globalsessionguid:<guid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
NoLogo="$(NoLogo)"
NoStandardLib="$(NoCompilerStandardLib)"
NoWin32Manifest="$(NoWin32Manifest)"
NullableContextOptions="$(NullableContextOptions)"
Nullable="$(Nullable)"
Optimize="$(Optimize)"
Deterministic="$(Deterministic)"
PublicSign="$(PublicSign)"
Expand Down
12 changes: 6 additions & 6 deletions src/Compilers/Core/MSBuildTaskTests/CscTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public void NullableReferenceTypes_Enabled()
{
var csc = new Csc();
csc.Sources = MSBuildUtil.CreateTaskItems("test.cs");
csc.NullableContextOptions = "enable";
csc.Nullable = "enable";
Assert.Equal("/nullable:enable /out:test.exe test.cs", csc.GenerateResponseFileContents());
}

Expand All @@ -347,7 +347,7 @@ public void NullableReferenceTypes_Disabled()
{
var csc = new Csc();
csc.Sources = MSBuildUtil.CreateTaskItems("test.cs");
csc.NullableContextOptions = "disable";
csc.Nullable = "disable";
Assert.Equal("/nullable:disable /out:test.exe test.cs", csc.GenerateResponseFileContents());
}

Expand All @@ -356,7 +356,7 @@ public void NullableReferenceTypes_Safeonly()
{
var csc = new Csc();
csc.Sources = MSBuildUtil.CreateTaskItems("test.cs");
csc.NullableContextOptions = "safeonly";
csc.Nullable = "safeonly";
Assert.Equal("/nullable:safeonly /out:test.exe test.cs", csc.GenerateResponseFileContents());
}

Expand All @@ -365,7 +365,7 @@ public void NullableReferenceTypes_Warnings()
{
var csc = new Csc();
csc.Sources = MSBuildUtil.CreateTaskItems("test.cs");
csc.NullableContextOptions = "warnings";
csc.Nullable = "warnings";
Assert.Equal("/nullable:warnings /out:test.exe test.cs", csc.GenerateResponseFileContents());
}

Expand All @@ -374,7 +374,7 @@ public void NullableReferenceTypes_Safeonlywarnings()
{
var csc = new Csc();
csc.Sources = MSBuildUtil.CreateTaskItems("test.cs");
csc.NullableContextOptions = "safeonlywarnings";
csc.Nullable = "safeonlywarnings";
Assert.Equal("/nullable:safeonlywarnings /out:test.exe test.cs", csc.GenerateResponseFileContents());
}

Expand All @@ -383,7 +383,7 @@ public void NullableReferenceTypes_Default_01()
{
var csc = new Csc();
csc.Sources = MSBuildUtil.CreateTaskItems("test.cs");
csc.NullableContextOptions = null;
csc.Nullable = null;
Assert.Equal("/out:test.exe test.cs", csc.GenerateResponseFileContents());
}

Expand Down

0 comments on commit 2d52a58

Please sign in to comment.