-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Automatically add references to core framework assemblies when targeting .NET Framework #379
Automatically add references to core framework assemblies when targeting .NET Framework #379
Conversation
…ing .NET Framework
<_TargetFrameworkMinorVersion Condition="$(_TargetFrameworkVersionSegmentCount) > 1">$(TargetFrameworkVersion.Split('.')[1])</_TargetFrameworkMinorVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup Condition=" '$(DisableImplicitFrameworkReferences)' != 'true' and '$(TargetFrameworkIdentifier)' == '.NETFramework'"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is bigger than the original set of default references in project.json/DNX. How were these chosen? Based on the .NET Framework default template today? Can we make this a bit smaller?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the .NET Framework default template today?
Yes, that's what I based it on. However, I'm suggesting that we make it even bigger by default, to include all the types that are in .NET Standard 2.0. That way you'll have access to all .NET Standard 2.0 types by default whether you are targeting .NET Core or .NET Framework.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Migration currently adds the default refs from project.json. If we land on a superset of that, then we should adjust the migration. File a bug on CLI for that.
<_TargetFrameworkMajorVersion>$(TargetFrameworkVersion.Split('.')[0])</_TargetFrameworkMajorVersion> | ||
<_TargetFrameworkMajorVersion Condition="$(_TargetFrameworkMajorVersion.StartsWith('v'))">$(TargetFrameworkVersion.Substring(1))</_TargetFrameworkMajorVersion> | ||
<_TargetFrameworkMinorVersion Condition="$(_TargetFrameworkVersionSegmentCount) > 1">$(TargetFrameworkVersion.Split('.')[1])</_TargetFrameworkMinorVersion> | ||
</PropertyGroup> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this string manipulation is necessary. IIRC, @rainersigwald mentioned elsewhere that MSBuild can will automagically compare System.Version-parseable strings and compare them as such.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is true, though System.Version.TryParse
will fail on a v
-prefixed string so you'll probably need to do that still.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rainersigwald What's the syntax to compare version numbers in MSBuild? Or do strings that parse as version numbers automatically get compared as such?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The latter: strings that parse as version numbers get compared that way with the usual comparison operators.
<Reference Include="Microsoft.CSharp"/> | ||
<Reference Include="System.Data"/> | ||
<Reference Include="System.Net.Http" Condition="($(_TargetFrameworkMajorVersion) > 4) Or ($(_TargetFrameworkMajorVersion) == 4 And $(_TargetFrameworkMinorVersion) >= 5)"/> | ||
<Reference Include="System.Xml"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: sort these alphabetically.
<Reference Include="System.Data.DataSetExtensions"/> | ||
<Reference Include="Microsoft.CSharp"/> | ||
<Reference Include="System.Data"/> | ||
<Reference Include="System.Net.Http" Condition="($(_TargetFrameworkMajorVersion) > 4) Or ($(_TargetFrameworkMajorVersion) == 4 And $(_TargetFrameworkMinorVersion) >= 5)"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are other conditions needed for version < 4, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests won't pass with version < 4 but that's only because of dotnet/msbuild#1333 combined with tests always running with core msbuild as of now. We keep getting requests for it, so we shouldn't discount version < 4 here.
Also update the test to make sure there aren't any warnings about references that can't be found
I've updated the list of references to be based on what is necessary to make the types in .NET Standard available, based on this list: https://github.com/dotnet/standard/tree/master/platforms/net461 From that list, I've excluded I've also added conditions to the references so that warnings won't be generated when you target .NET Framework 3.5 or 4.0, which don't have all of these assemblies. I've also sorted them. |
@nguerrera This is ready for you to re-review now |
<Reference Include="System.Core"/> | ||
<Reference Include="System.Data"/> | ||
<Reference Include="System.Drawing"/> | ||
<Reference Include="System.IO.Compression.FileSystem" Condition=" '$(_TargetFrameworkVersionWithoutV)' >= '4.5' "/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe worth a comment that these comparisons actually do the right thing in msbuild
<Reference Include="System.Numerics" Condition=" '$(_TargetFrameworkVersionWithoutV)' >= '4.0' "/> | ||
<Reference Include="System.Runtime.Serialization"/> | ||
<Reference Include="System.Xml.Linq"/> | ||
<Reference Include="System.Xml"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
project.json had Microsoft.CSharp, should we do that if we're in a C# project?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a strong opinion, but I left it out because it's not currently included in .NET Standard.
Also, is there a bug on the CLI to remove now redundant references from migration. What will be the behavior for migrated projects from the current preview when they get the next one and start to have dup references? |
I filed dotnet/cli#4695 to remove the redundant references. Duplicate references don't appear to be a problem, I think MSBuild ends up merging them. |
Update BuildTools
* Tags become choices, lots of help changes * Rebased on rel/sv2017/post-rtw * Post-Rebase cleanup of outputs for various situations. Moved tags to symbols on 2.0 templates * Reverted to tags in 1.x templates and Item templates * Removed extra space from tags secifications in 1.x templates * Reverted to tags in 2.0 templates * Fixed misspelling of 'language' in 2.0 template.json files * Changes based on review comments (not including case-insensitive reads yet) * Rebased on rel/vs2017/post-rtw * Made reading template config & cache info be case-insensitive. * Made cache parameter properties get only * Cleanup of help & ItemplateInfo * Minor cleanup, mostly removing no longer needed async tasks * More cleanup * Tags become choices, lots of help changes * Rebased on rel/sv2017/post-rtw * Post-Rebase cleanup of outputs for various situations. Moved tags to symbols on 2.0 templates * Reverted to tags in 1.x templates and Item templates * Removed extra space from tags secifications in 1.x templates * Reverted to tags in 2.0 templates * Fixed misspelling of 'language' in 2.0 template.json files * Cleaning up UI interactions. Better experience for: problems with extra args files (dotnet#327, dotnet#329); default not in choice list dotnet#271 * Added support for split template configuration files (dotnet#150) * Cleanup of nulls in the template cache * fixed a merge mistake * More fixes from merge issues * Make fallback host files work correctly * Added wildcard to host matched. Fixed a bug with wildcard matching in zips * Add filter switch, hide all switch, add logic for accepting explicitly set filters * Change filter to type * Give instructions to call --help instead of showing help on error * Remove unused using * Fixes dotnet#380 and dotnet#379 * Respond to review feedback * Make the message shown for the invalid params match between help and non-help cases * Set IsPackable=false for new test projects (dotnet/templating#376). The rationale for this is that creating NuGet packages from tests is probably not the more-common use case and so by default these project should not participate when "dotnet pack" is run at the solution level. This doesn't prevent users from opting into "dotnet pack", it simply won't be the default. * Make IsPackable configurable for test project template (dotnet/templating#377). * Use '-p' as the short form for '--enable-pack' in MSTest v1 project template. * Implement "--enable-pack" parameter for test project templates (dotnet/templating#377). This parameter, if set to "true", marks the project as packable (i.e. participates in solution-level calls to "dotnet pack", producing a NuGet package). * Build for non-Windows platforms Refactor to use latest cli Add RestoreSource for dotnet-new3 project Build with framework version and runtime id Fix test cases * Move testbase location to local directory * Updating the identity of the 2.0 templates * Better matching across templates with same group identity. * Added precedence to all template.json files * Reading & writing template Precedence * Template matching uses Precedence to help disambiguate templates * fix for dotnet#395 * Updated package refs in test projects * fix for exclude, include, & copy only configuration in sources * Mikes test harness for testing dotnet new commands. Tests for precedence disambiguation * Fixes per Mike's CR * renamed the mvc precendence tests * Add 3PN for nuget.exe * Allow runtime to be passed in * Handling reading different cache formats, and upgrading the cache aut… (dotnet#407) * Handling reading different cache formats, and upgrading the cache automatically as needed * Cleanup for cache versioning * Improvements to cache versioning. Language display fix. * Cache rebuild enhancement. Only scan mount points for templates and langpacks
Right now, if you create an ASP.NET Core application targeting .NET Framework, you won't get references to any framework assemblies except mscorlib. This means a bunch of types (
Uri
, Linq, etc) won't be available to you.We could add these to the templates, but in the interest of keeping the
.csproj
files concise I think it's better to reference them automatically in the SDK targets. That's what this PR does.The list of assemblies comes from what you get by default when creating a new .NET Framework Class Library. For parity with .NET Standard and .NET Core projects, I'd suggest we should reference all assemblies that contain types that are in .NET Standard 2.0. @weshaggard @ericstj @terrajobst can you provide a list of assemblies you would need to reference in .NET Framework to get all the types that are in .NET Standard 2.0?