-
Notifications
You must be signed in to change notification settings - Fork 8
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
Embedded activation of C#8 and NUllable feature in the package. #14
Conversation
Hey, sorry for the late reply. I totally missed the notification for this PR. Feel free to @ me the next time if I don't reply after a few days. I see where you are coming from with this PR and I agree that something like this may make adopting nullable reference types easier for some people, but I think that making these changes would introduce feature creep to the package. Imo, NuGet packages should not arbitrarily change project system defaults. This can quickly become an issue for a user who needs to trace down why a default value established by .NET's project system is suddenly different. It's also impossible to predict every single use-case with this package. Maybe the proposed defaults will create some issues for some exotic project configuration. I think that the best route is to simply not change any kind of defaults, if possible. In addition, I think that your desired behavior is easily replicated per-project by using a <LangVersion>latest</LangVersion>
<Nullable>annotations</Nullable> By creating such a file, you don't have to (re-)configure NRTs in each project, making the whole setup for a solution incredibly simple and quick. If that doesn't satisfy your needs, I also have another suggestion, but it's untested and I have no idea whether it actually works! If you want to have a NuGet package which provides these project defaults, you could try to create an entirely new NuGet package which is a dev-dependency and references I am going to close the PR for the reasons named above, but I want to thank you for taking the time to create the PR. I really appreciate the intention and the fact that you wanted to contribute here! ❤️ I just think that such changes are too heavy for a slim package like Nullable. |
@manuelroemer Ok thanks for your response. So if not changing the Finally for the solution of creating a package that reference I look a bit and found that we can still change that default behaviour with some modifications in A last idea that comes to my mind: maybe the best to create those packages is to not reference |
One more remarks:
However conditions on the target projects are not working when put in In real I don't need all that conditions since I don't use all that targets in the projects I should maintain. But it's enough complex to make me want to hide that complexity in some package. |
Hi, thanks for the reply! I want to tackle your last point first:
I must ask you a follow-up question here: Why aren't you simply using the following <PropertyGroup>
<LangVersion>latest</LangVersion>
<Nullable>annotations</Nullable>
</PropertyGroup> This is exactly the same configuration which you would also get via the NuGet package if I had accepted this PR. |
Now to get to the other points (I'll just go through them in order):
To be honest, I disagree with this claim. On the other hand, having project settings being written by a NuGet package is magic. It's something that rarely happens (if ever) and that your typical developer doesn't expect. And in comparison to a At last, a personal opinion. Since I don't know your exact project setup, it might not apply to you at all. I'm simply saying the following because it might help to understand my point of view on the discussion.
Of course, that sounds great! Any contribution here is much appreciated. 🍻
Do you have any additional suggestions/wishes? I'm always open to dicuss them - the above is just the result of brainstorming quickly!
This is actually really interesting - thanks for the link! I will have a look at it when I find the time. I want to introduce a If you need the changes immediately, you can consider forking the project, but I really recommend you to abuse the |
That was a lot of text - I hope that all of this helps you in some way/that we can come to a good solution here. I'm quite eager to hear your thoughts on the topic! 😄 |
First I want to says that it's a pleasure to exchange with you. It's long text yes, but if it's needed to find the best solutions it's worth it. So first, why I don't want to have just a simple This typically happens when using string.IsNullOrEmpty()
If we build that sample we get one warning on last line ( So the solution is to have a variable activation of the nullable feature in function of the target framework, which is what this PR was trying to achieve. If you look back at it in details it do not affect the same default to all frameworks. This allow to get warnings only against annotated frameworks, and remove false positive warnings made by build from legacy frameworks. We can says that legacy frameworks builds trust recent frameworks builds to produce the warnings. And it's why I would have preferred NuGet packages: because they are more adapted to select thinks in function of the targeted framework than So the whole point is not to use But now I explain all that more in details (to you and also another time to myself) I start to wonder if in real what we want is not to activate nullable warnings only for the most recent framework of a project.
because net5 is probably more annotated than netcoreapp3.x, the issue I got with legacy frameworks may also apply to netcoreapp3.x versus net5. Now, I see just one things that this nuget package can do to simplify this, which is to make this package set
But this would require that you change your mind about changing default values for some properties... I'm please that you were not agree to go in that direction first since anyway the solution will be better than what I suggest first. |
And by the way, for a migration in progress, using I think that it's better to really enable the feature and disable it in all existing files by adding a So yes it do not show when a project is in progress or finished, but at least we can found where we have things to migrate, and track the progression by counting the number of files that are still starting by this directive. |
@manuelroemer I won't bother you anymore with this PR, I'm now fully convinced that we should not modify the package like that. Thanks for your patience |
Sorry again for the late reply, I had limited access to my PC for the last week. I also want to tell you that it's been a very pleasant exchange in my opinion - thank you a lot for your thorough answers and for taking the time to discuss everything! |
I discover this package after having read this blog post:
https://endjin.com/blog/2020/07/dotnet-csharp-8-nullable-references-supporting-older-runtimes
It clearly simplify a lot the support of a private enterprise library because before that we were using a lot of
#if
instructions to annotate the library for recent frameworks and keep supporting older frameworks.But in that blog post there is a trick which is not easy to guess and on which this package could help:
The variability of the activation level of the feature:
<Nullable>enable</Nullable>
vs<Nullable>annotations</Nullable>
Note that we have a lot of libraries in which we want to add support of nullable, and that this scenario is probably the most common one for people looking for a package like that one. So I though it could be great if the package natively guide us in that direction.
It worked fine in multiple use cases I've tested, and we can override it in csproj if we want.
The only limitation i've found is on legacy csproj (not SDK style) where the
Nullable
tag seems to be not interpreted, but theLangVersion
tag works so even in that case it's already a better experience for the developer since he could work with nullable right after having added the package (by using#nullable
directive in the cs files), it's no more required for him to set the LangVersion manually.