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

Add support for NullableReferenceTypes build setting #4058

Open
jcouv opened this Issue Sep 27, 2018 · 9 comments

Comments

Projects
None yet
6 participants
@jcouv
Copy link
Member

jcouv commented Sep 27, 2018

This is a tracking work item related to the "nullable reference types" feature in C# 8.0 (for dev16).
We'll add design notes here as it crystallizes (is it a property or some other form of API?)
Tagging @davkean

@cston cston referenced this issue Sep 27, 2018

Open

[Work items] Nullable reference types #22152

50 of 148 tasks complete

@jcouv jcouv added this to the 16.0 milestone Sep 27, 2018

@jcouv

This comment has been minimized.

Copy link
Member Author

jcouv commented Nov 3, 2018

The design for turning on the nullable feature changed since our last discussion.
Previously, we would have [NonNullTypes] (for class- or method-level control) or [module:NonNullTypes] (for module/project-level).
Now, we'll have #nullable ... for scoped control in source, and a compiler flag for project-level control. That compiler flag is exposed via MSBuild property NullableReferenceTypes, as part of dev16 preview1.

Based on this, there are two scenarios of interest:

  1. exposing a checkbox in Build options ("Enable Nullable Reference Types")
  2. allowing a codefixer to change this project property (like UpgradeProject does for LangVersion)

@davkean I assume that those scenarios translate into three work items:

  1. some common work in project-system (object model or API change)
  2. IDE work to add Build option UI (or is this also owned by project-system)
  3. codefixer work (IDE/myself)

@davkean @Pilchie Do you think the API work (1) could be reasonably scheduled as part of preview 2? If yes, I would do the codefixer (3) in preview 2 as well.

@jcouv jcouv changed the title Add support for module-level NonNullTypes Add support for NullableReferenceTypes build setting Nov 3, 2018

@jcouv

This comment has been minimized.

Copy link
Member Author

jcouv commented Nov 12, 2018

Tagging @tmeschter per email discussion about preview2 goals. Thanks

davkean added a commit to davkean/project-system that referenced this issue Nov 15, 2018

Add NullableReferenceTypes property
Fixes configuration property portion dotnet#4058

This can be acccesed using:

Project.ConfigurationManager.ConfigurationRow(configurationName).Item(1).Properties["NullableReferenceTypes"]

davkean added a commit to davkean/project-system that referenced this issue Nov 15, 2018

Add NullableReferenceTypes property
Fixes adding configuration-specific property for dotnet#4058

Note: This is a configuraiton-specific property but writes itself without a configuration condition, similar to LangVersion. We need this because it's going to live on the Build property page which pulls from configuration.

You can access this using DTE.Configuration.Properties["NullableReferenceTypes"]. We do not yet have a strongly typed API for it and will do that when legacy adds support for it.
@etbyrd

This comment has been minimized.

Copy link
Contributor

etbyrd commented Nov 19, 2018

I could get a PR out for the checkbox in the Build property page - do we have an idea of where on the page we would want it?

@jcouv

This comment has been minimized.

Copy link
Member Author

jcouv commented Nov 19, 2018

For adding the checkbox to the Build property page, I think putting it under "Check for arithmetic overflow/underflow" would make sense.
@davkean Does that sounds ok?

image

@tmeschter

This comment has been minimized.

Copy link
Contributor

tmeschter commented Nov 19, 2018

I wouldn't want to add the checkbox without adding the underlying property support to csproj/msvbprj, and that's the expensive part.

@chucker

This comment has been minimized.

Copy link

chucker commented Dec 5, 2018

In my testing, it looks like the <NullableReferenceTypes> property only works with new-style projects. Are there plans to make it work with the old project system (e.g., for an ASP.NET project which can't be migrated due to #2670)?

@jcouv

This comment has been minimized.

Copy link
Member Author

jcouv commented Dec 6, 2018

@chucker Yes, this property will be made to work in old project system too, before C# 8 ships as RTM, but likely after dev16.0 (where C# 8.0 language features are in beta).
The present issue tracks this remaining work.

@jcouv

This comment has been minimized.

Copy link
Member Author

jcouv commented Dec 19, 2018

@davkean We had to modify the options to add a third one (true/false were not enough) and changed the name of the option in the process.
I assume that the change of name affects project system, but the change of values doesn't. Let me know if that's not the case, as one of the options might still change.
Sorry for the randomization.

Through msbuild the context could be set by supplying an argument for a "NullableContextOptions" parameter of Csc build task. Accepted values are "enable", "disable", "safeonly", 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.

https://github.com/dotnet/roslyn/blob/master/docs/features/nullable-reference-types.md#setting-project-level-nullable-context

@Tragetaschen

This comment has been minimized.

Copy link

Tragetaschen commented Feb 5, 2019

Given how I spent the last thirty minutes, it might be worth going through the existing blogs and docs for C# 8 and modify the samples on how to set up that feature. That property name change and the new option names took quite some time to figure out.

Some examples are https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/nullable-reference-types or https://blogs.msdn.microsoft.com/dotnet/2018/12/05/take-c-8-0-for-a-spin/

@jjmew jjmew modified the milestones: 16.0, 16.X Feb 13, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment