* Don't use Targets* helper properties in libs projs
This change makes it possible to migrate 200+ (ref+src) projects to use
TargetFramework instead of TargetFrameworks which avoids the additional
outer build evaluation and invocation which ultimately makes the overall
build faster.
Targets* properties (i.e. TargetsWindows, TargetsAnyOS, TargetsUnix,
etc.) rely on the TargetFramework property which usually are set
inside a project. The TargetFramework property is only
available before a project specifies it if it's explicitly set in a props
file or if the project is cross-targeting and the outer-build dispatches
into the inner-build. During the dispatch, the TargetFramework property
is passed in as a global property.
Until now that behavior wasn't a problem because every libraries project
cross-targeted (by setting the TargetFrameworks property) even though
many only include a single TargetFramework (i.e. NetCoreAppCurrent).
To allow projects to use the TargetFramework property instead of
TargetFrameworks, the Targets* helper properties can't be calculated
anymore early in a props file as the TargetFramework property isn't set
at that time.
In general, the guidance by the SDK/msbuild team is to not read from the
TargetFramework property before the project sets it
(in a property group). That effectively means that the TargetFramework
property shouldn't be used in props files at all.
Therefore these helper properties can't be used anymore for property
conditions and I'm replacing their usage with TargetPlatformIdentifier
comparisons for both properties and items.
In nearly all cases, the Targets* helper properties can be replaced with
TargetPlatformIdentifier checks on items and in the few cases where
TargetsUnix or TargetsLinux marks multiple tfms as compatible, the exact
tfms must be used instead for the TargetPlatformIdentifier comparison.
Whenever a project needs to condition properties on the platform, I'm
first setting the TargetPlatformIdentifier the same way the SDK sets it
so that the SDK later doesn't need to set it again to avoid the
additional expensive msbuild function call.
* Use TargetFramework singular to avoid outer builds
Use TargetFramework instead of TargetFrameworks property whenever a
projects only targets a single target framework. This avoid unnecessary
outer builds and evaluations and makes the build faster.
* Bump version of C# compiler
This should be reverted when arcade brings in a new enough compiler.
* Fix a few new warnings from updating compiler
* Enable IDE0190 to employ parameter null checking
* Initial roll out of !!
* Fix more compiler warnings from upgrade, plus some test fixes / reverts
* Fix a few more tests
* Disable profiling test
* Add NetCoreAppCurrent rid agnostic tfm to libs
This change adds a NetCoreAppCurrent rid-less configuration which throws
a PNSE to the following libraries:
- System.Console
- System.IO.Compression.ZipFile
- System.IO.Compression
- System.IO.FileSystem.DriveInfo
- System.IO.MemoryMappedFiles
- System.Net.Http
- System.Net.Mail
- System.Net.NameResolution
- System.Net.Primitives
- System.Net.Requests
- System.Net.WebSockets
System.Private.Runtime.InteropServices.JavaScript is excluded from that
list as it doesn't have a contract and hence can't generate a PNSE
assembly. Also it's currently a private assembly.
These are the only libraries that were missing a RID agnostic tfm.
Adding rid-less configurations, even if they just throw PNSEs helps with:
- Platform enablement, i.e. a new "base" platforms like "Browser" usually
require libraries that are RID specific to support them. By offering a
RID agnostic PNSE tfm, projects can gradually support new platforms.
- Making it possible to have ProjectReferences between libraries, i.e.
imagine an microsoft.build.notargets / microsoft.build.traversal
project with a `$(NetCoreAppCurrent)-$(TargetOS)` tfm which P2Ps all
source projects. NuGet can't know that a $(NetCoreAppCurrent)-Linux
tfm can reference a project with a $(NetCoreAppCurrent)-Unix tfm and
will throw during restore, more precisely during the compatibility
check. Ideally NuGet or the SDK would support targeting platforms from
the runtime.json RID graph, including its compatiblity matrix but
that isn't the case today.
Even though the added tfms add to the build, I have other changes
in the pipeline which depend on this one which will make the build
noticeably faster.
* Use default impl for DriveInfo & ZipFile
Adds ArgumentException.ThrowIfNullOrEmpty and then uses it in a bunch of places around the tree. Most of the replaced places used a resource string for the message, and I used it in places where it didn't feel like we were losing any meaningful information by centralizing on the single shared string, but I didn't use it in places where the resource string message used in the empty case conveyed something that seemed useful, e.g. a recommendation on what to use instead of an empty string.
There are a few places where I allowed for order of exception throws to change in the case where there were multiple user errors and the validation for a single argument was split, e.g. I changed a few cases of:
```C#
if (arg1 is null) throw new ArgumentNullException(...);
if (arg2 is null) throw new ArgumentNullException(...);
if (arg1.Length == 0) throw new ArgumentException(...);
if (arg2.Length == 0) throw new ArgumentException(...);
```
to:
```C#
ArgumentException.ThrowIfNullOrEmpty(arg1);
ArgumentException.ThrowIfNullOrEmpty(arg2);
```
even though it'll produce a different exception for `M("", null)` than it would previously. Technically a breaking change, but given this is a case of multiple usage errors and all the exceptions are ArgumentException-based, I think it's acceptable.
I wanted to get this in before we do the massive !! conversion, as I expect !! auto-fixes will make it a bit harder to roll this out. I explicitly did not do anything to roll out use of ArgumentNullException.ThrowIfNull, except in cases where I was modifying a method to use ArgumentException.ThrowIfNullOrEmpty, in which case for consistency I changed anything else in the function that could have been using ThrowIfNull to do so.
* ignoring leading dot when comparin cookie domain
* Simplify cookie comparing logic to equality and moving it to CookieComparer to fix the build
* Domain comparing optimizarion and more unit tests
* small check optimization
* Renaming method
Update slngen tooling to latest stable version and solution files since
a lot changed since the last time they were updated:
- NET7 (removal of older TFMs)
- Source Generators
With the newest udpate of slngen, the order of elements (configuration, folders, etc.) is in sync with how Visual Studio arranges them.
Also the order is now deterministic.
Based on that, updating all solution files to have the correct ordering of elements. This change also unblocks adding CI protection for
making sure that solution files are up-to-date in regards to their dependencies as slngen is now generating the files deterministically.
Fixes https://github.com/dotnet/runtime/issues/56847
The `EventSource_ExistsWithCorrectId` test requires the event source
switch be set to true to work correctly after aggressive linking.
* Remove old fwlink from Obsolete messages and make message improvements
* Thorough review and update of Obsolete messages
* Cleanup
* Make messages about unsupported APIs more consistent
* Update RequiresUnreferencedCodeAttribute messages to be consistent between ref and src
* Cleanup
* Cleanup
* Use 'not supported' instead of 'no longer supported'
* Omit unnecessary error:false from Obsolete attributes. Fix message typo.
* Remove old comment
* PR feedback
ArrayList.ToArray(Type) has to lookup the array type in the type loader structures. It makes it slow and potentially AOT unfriendly since the code required to support the array type may not exist.
Convert most uses of ArrayList.ToArray in libraries to use List<T> if possible, or ArrayList.CopyTo if the conversion to List<T> was not straightforward.
Simplified a few other places that created arrays while I was on it.
* replacing GetLastWin32Error with GetLastPInvokeError in remaining assemblies
* replace GetLastWin32Error with GetLastPInvokeError in assemblies outside system.private.corelib
* Apply suggestions from code review
Co-authored-by: Jan Kotas <[email protected]>
SocketAddressTest.ToString_UnsupportedFamily_Throws test fails on Android in case of AddressFamily.Packet and AddressFamily.ControllerAreaNetwork because it expects PNSE for both address family types but there is no any exception thrown.
This change disables the mentioned test on Android due to different behavior. Also, I'm not sure whether the test has right name.
#47911 (comment)
We have a bunch of test assemblies that don't make sense on some platforms, e.g. Browser.
Right now we're skipping them via `[SkipOnMono("reason", TestPlatforms.Browser)]` but there's nothing that inherently ties this to Mono other than the current implementation.
The more generic `SkipOnPlatform` attribute can be used instead.
We can also use it in places where we do `[PlatformSpecific(~TestPlatforms....)]` to avoid the double inversion.
* Fix various places that assumed host byte order was little-endian,
use appropriate host <-> network byte order conversion instead.
* This in particular affects handling of IPv4 addresses, which
are stored internally in network order.
* Fix endian assumptions in socket option code (GetSockOpt).
* Update test cases and provide /proc test files from a
big-endian system.
* Use [NotNullWhen(true)] in more places
Did a quick search/audit for methods that returned bool and took nullable object as the first input, and added [NotNullWhen(true)] where it was obviously correct.
* Address PR feedback
This changes the DateTime parsing to not convert the parsed Expires value to a Local datetime, potentially adding hours to it and making it invalid if it surpasses `DateTime.MaxValue`.
Fixes#45491
* Remove unnecessary OrderBy / copy from MemoryCache.Compact
* Replace First() in ILEmitResolverBuilder with [0]
* Remove stale "using System.Linq;" from System.Text.Json
* Remove stale "using System.Linq;" from System.Security.Cryptography.X509Certificates
* Remove some LINQ usage from System.Security.Cryptography.Pkcs
* Remove System.Linq reference from System.Private.Xml
* Remove System.Linq reference from System.Net.WebHeaderCollection
* Remove stale "using System.Linq;" from CookieContainer
* Remove stale "using System.Linq;" from AltSvcHeaderParser
* Remove Enumerable.Contains on a string from System.IO.Packaging
* Remove System.Linq dependency from System.Diagnostics.Process
* Remove LINQ usage from Microsoft.Extensions.Options
* Remove LINQ usage from Microsoft.Extensions.Logging
* Remove LINQ usage from Microsoft.Extensions.Logging.Console
* Remove LINQ from CollectionExtensions.GetAssets/RuntimeFiles
* Update src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Rfc3161TimestampToken.cs
Co-authored-by: Jeremy Barton <[email protected]>
Co-authored-by: Jeremy Barton <[email protected]>
At some point some Debug.Asserts/Fails were replaced by this NetEventSource.Fail helper, which both Debug.Fails and fires an EventSource event. But asserts in our code base are intended for things that should never happen, and we needn't be emitting events for them (if we did want to emit events for them, we'd need to tackle the other ~20,000 Debug.Assert/Fails in the codebase.
I've deleted NetEventSource.Fail, and fixed up the call sites. Some were simply replaced by Debug.Assert/Fail. Some were deleted entirely, when from code inspection it looked like they could actually be hit, but were guarded by a check for the event source being enabled and thus were unlikely to have been triggered in our previous testing. Etc.
* Fix various typos
* `occurence`, `occurance` -> `occurrence`
* `accross` -> `across`
* `adddress`, `addresss` -> `address`
* `alignement`, `aligment` -> `alignment`
* Remove `c` from triple c.
* Remove `s` from triple s.
* In palsuite, `Successs` (with triple s) was in commented out
`Trace()` message, removed all commented out `Trace()` calls
from such files.
* Fix invalid markdown in `unix-test-instructions.md`.
* Revert event source change