Skip to content
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

Use ProjectReferences in inbox src projects #106329

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions docs/coding-guidelines/project-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,9 @@ All ref outputs should be under
`bin\$(MSBuildProjectName)\ref\$(TargetFramework)`

## src
In the src directory for a library there should be only **one** `.csproj` file that contains any information necessary to build the library in various target frameworks. All supported target frameworks should be listed in the `TargetFrameworks` property.
In the src directory for a library there should be only **one** `.csproj` file that contains any information necessary to build the library in various target frameworks. All supported target frameworks should be listed in the `TargetFramework` or `TargetFrameworks` property.

All libraries should use `<Reference Include="..." />` for all their references to libraries that compose the shared framework of the current .NETCoreApp. That will cause them to be resolved against the locally built targeting pack which is located at `artifacts\bin\microsoft.netcore.app.ref`. The only exception to that rule right now is for partial facades which directly reference System.Private.CoreLib and thus need to directly reference other partial facades to avoid type conflicts.

Other target frameworks than .NETCoreApp latest (i.e. `netstandard2.0`, `net462`, `net6.0`) should use ProjectReference items to reference dependencies.
Libraries should use `ProjectReference` items to reference live dependencies.

### src\ILLink
Contains the files used to direct the trimming tool. See [ILLink files](../workflow/trimming/ILLink-files.md).
Expand Down
5 changes: 4 additions & 1 deletion eng/configure-toolset.ps1
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Working around issue https://github.com/dotnet/arcade/issues/2673
$script:DisableNativeToolsetInstalls = $true
$script:DisableNativeToolsetInstalls = $true

# TEMP CHANGE
$script:useInstalledDotNetCli = $false
5 changes: 4 additions & 1 deletion eng/configure-toolset.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Working around issue https://github.com/dotnet/arcade/issues/2673
DisableNativeToolsetInstalls=true
DisableNativeToolsetInstalls=true

# TEMP CHANGE
useInstalledDotNetCli=false
2 changes: 1 addition & 1 deletion eng/generators.targets
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
(
'$(DisableImplicitFrameworkReferences)' == 'true' and
(
'@(Reference->AnyHaveMetadataValue('Identity', 'System.Runtime.InteropServices'))' == 'true' or
'@(ProjectReference->AnyHaveMetadataValue('Filename', 'System.Runtime.InteropServices'))' == 'true' or
'@(ProjectReference->AnyHaveMetadataValue('Identity', '$(CoreLibProject)'))' == 'true'
)
)" />
Expand Down
15 changes: 0 additions & 15 deletions eng/packaging.targets
Original file line number Diff line number Diff line change
Expand Up @@ -203,21 +203,6 @@
</ItemGroup>
</Target>

<Target Name="WarnOnProjectReferenceToFrameworkAssemblies"
BeforeTargets="IncludeTransitiveProjectReferences"
Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)' and
'@(ProjectReference)' != ''">
<!-- Find project references that overlap with NetCoreApp, are direct (NuGetPackageId is not set), actually referenced (ReferenceOutputAssembly), and not hidden with PrivateAssets
ProjectReferences can opt out of this checking by setting AllowFrameworkPackageReference, though they should not. -->
<Warning Text="Project reference '%(ProjectReference.Identity)' is a reference to a framework assembly and is not required in $(NetCoreAppCurrent) (NetCoreAppCurrent)."
Code="NETPKG0001"
Condition="$(NetCoreAppLibrary.Contains('%(ProjectReference.Filename);')) and
'%(ProjectReference.ReferenceOutputAssembly)' != 'false' and
'%(ProjectReference.NuGetPackageId)' == '' and
'%(ProjectReference.PrivateAssets)' != 'all' and
'%(ProjectReference.AllowFrameworkPackageReference)' != 'true'" />
</Target>

<Target Name="GenerateMultiTargetRoslynComponentTargetsFile"
Inputs="$(MSBuildProjectFullPath);$(_MultiTargetRoslynComponentTargetsTemplate)"
Outputs="$(MultiTargetRoslynComponentTargetsFileIntermediatePath)">
Expand Down
41 changes: 22 additions & 19 deletions eng/references.targets
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<Project>

<PropertyGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<!--
Disable RAR from transitively discovering dependencies for references. This is required as we don't copy
Expand All @@ -14,34 +15,35 @@
</ProjectReference>
</ItemDefinitionGroup>

<!-- Set the corresponding CoreLib runtime configuration. -->
<ItemGroup Condition="'@(ProjectReference)' != ''">
<_coreLibProjectReference Include="@(ProjectReference->WithMetadataValue('Identity', '$(CoreLibProject)'))" />
<ProjectReference Update="@(_coreLibProjectReference)"
Private="false">
<ProjectReference Update="@(_coreLibProjectReference)">
<SetConfiguration Condition="'$(RuntimeFlavor)' == 'CoreCLR' and
'$(Configuration)' != '$(CoreCLRConfiguration)'">Configuration=$(CoreCLRConfiguration)</SetConfiguration>
<SetConfiguration Condition="'$(RuntimeFlavor)' == 'Mono' and
'$(Configuration)' != '$(MonoConfiguration)'">Configuration=$(MonoConfiguration)</SetConfiguration>
</ProjectReference>
<!-- If a CoreLib ProjectReference is present, make all P2P assets non transitive. -->
<ProjectReference Update="@(ProjectReference->WithMetadataValue('PrivateAssets', ''))"
PrivateAssets="all"
Condition="'$(IsSourceProject)' == 'true' and '@(_coreLibProjectReference)' != ''" />
</ItemGroup>

<!-- Make shared framework assemblies not app-local (non private). -->
<Target Name="UpdateProjectReferencesWithPrivateAttribute"
AfterTargets="AssignProjectConfiguration"
BeforeTargets="PrepareProjectReferences"
Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and
('$(IsTestProject)' == 'true' or '$(IsTestSupportProject)' == 'true') and
'@(ProjectReferenceWithConfiguration)' != ''">
<ItemGroup>
<ProjectReferenceWithConfiguration PrivateAssets="all"
Private="false"
Condition="$(NetCoreAppLibrary.Contains('%(Filename);')) and '%(ProjectReferenceWithConfiguration.Private)' == ''" />
</ItemGroup>
</Target>
<!-- Mark shared framework assemblies as non-transitive (privateassets=all) and non app-local (private=false). -->
<ItemGroup Condition="'@(ProjectReference)' != '' and
'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and
'$(TargetFrameworkVersion)' == 'v$(NetCoreAppCurrentVersion)'">
<_ProjectReferenceWithOriginalIdentity Include="@(ProjectReference)"
OriginalIdentity="%(Identity)" />
<_projectReferenceWithFilename Include="@(_ProjectReferenceWithOriginalIdentity->Metadata('Filename'))" />

<_projectReferenceExcludedWithFilename Include="@(_projectReferenceWithFilename)"
Exclude="@(NetCoreAppLibrary)" />
<_projectReferenceIncludedWithFilename Include="@(_projectReferenceWithFilename)"
Exclude="@(_projectReferenceExcludedWithFilename)" />

<ProjectReference Update="@(_projectReferenceIncludedWithFilename->Metadata('OriginalIdentity'))">
<PrivateAssets Condition="'%(PrivateAssets)' == ''">all</PrivateAssets>
<Private Condition="'%(Private)' == ''">false</Private>
</ProjectReference>
</ItemGroup>

<Target Name="ReplaceCoreLibSrcWithRefAssemblyForCompilation"
AfterTargets="FindReferenceAssembliesForReferences"
Expand All @@ -52,4 +54,5 @@
<ReferencePathWithRefAssemblies Include="@(_resolvedCoreLibProjectReference->Metadata('ReferenceAssembly'))" />
</ItemGroup>
</Target>

</Project>
1 change: 1 addition & 0 deletions eng/resolveContract.targets
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
<PropertyGroup>
<!-- Let GenFacades use roslyn from the toolset package as it loads sources which might require newer language features. -->
<GenFacadesUseRoslynToolsetPackagePath>true</GenFacadesUseRoslynToolsetPackagePath>
<GenFacadesReferencePathItemName>ReferencePathWithRefAssemblies</GenFacadesReferencePathItemName>
</PropertyGroup>

<!-- ##### GenAPI settings ##### -->
Expand Down
20 changes: 0 additions & 20 deletions eng/targetingpacks.targets
Original file line number Diff line number Diff line change
Expand Up @@ -89,26 +89,6 @@
Condition="'$(UseLocalAppHostPack)' == 'true' and '@(KnownAppHostPack->AnyHaveMetadataValue('TargetFramework', '$(NetCoreAppCurrent)'))' != 'true'" />
</ItemGroup>

<!-- Simple name references will be resolved from the targeting pack folders and should never be copied to the output. -->
<ItemGroup>
<Reference Update="@(Reference)">
<Private Condition="'%(Reference.Extension)' != '.dll'">false</Private>
</Reference>
</ItemGroup>

<!-- Add the resolved targeting pack to the assembly search path. -->
<Target Name="UseTargetingPackForAssemblySearchPaths"
BeforeTargets="ResolveAssemblyReferences;
DesignTimeResolveAssemblyReferences"
Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and
'$(TargetFrameworkVersion)' == 'v$(NetCoreAppCurrentVersion)' and
'$(DisableImplicitFrameworkReferences)' == 'true'">
<PropertyGroup>
<AssemblySearchPaths>$(AssemblySearchPaths);$(MicrosoftNetCoreAppRefPackRefDir.TrimEnd('/\'))</AssemblySearchPaths>
<DesignTimeAssemblySearchPaths>$(DesignTimeAssemblySearchPaths);$(MicrosoftNetCoreAppRefPackRefDir.TrimEnd('/\'))</DesignTimeAssemblySearchPaths>
</PropertyGroup>
</Target>

<!-- Use local targeting/runtime pack for NetCoreAppCurrent. -->
<Target Name="UpdateLocalTargetingAndRuntimePack"
Condition="'$(UseLocalTargetingRuntimePack)' == 'true'"
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<UseLocalTargetingRuntimePack Condition="'$(IsNETCoreAppAnalyzer)' == 'true'">false</UseLocalTargetingRuntimePack>
<!-- By default, disable implicit framework references for NetCoreAppCurrent libraries. -->
<DisableImplicitFrameworkReferences Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and
$([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '$(NETCoreAppCurrentVersion)')) and
'$(TargetFrameworkVersion)' == 'v$(NetCoreAppCurrentVersion)' and
('$(IsNETCoreAppRef)' == 'true' or '$(IsNETCoreAppSrc)' == 'true')">true</DisableImplicitFrameworkReferences>
<!-- Enable trimming for any source project that's part of the shared framework.
Don't attempt to trim PNSE assemblies which are generated from the reference source. -->
Expand Down
30 changes: 16 additions & 14 deletions src/libraries/Microsoft.CSharp/src/Microsoft.CSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -238,23 +238,25 @@
<Compile Include="Microsoft\CSharp\RuntimeBinder\ComInterop\VariantArgBuilder.cs" />
<Compile Include="Microsoft\CSharp\RuntimeBinder\ComInterop\VariantArray.cs" />
<Compile Include="Microsoft\CSharp\RuntimeBinder\ComInterop\VariantBuilder.cs" />

<Reference Include="System.Reflection.Emit" />
<Reference Include="System.Reflection.Emit.ILGeneration" />
<Reference Include="System.Reflection.Emit.Lightweight" />
<Reference Include="System.Reflection.Primitives" />
</ItemGroup>

<ItemGroup>
<Reference Include="System.Collections" />
<Reference Include="System.Collections.Concurrent" />
<Reference Include="System.Linq" />
<Reference Include="System.Linq.Expressions" />
<Reference Include="System.Memory" />
<Reference Include="System.ObjectModel" />
<Reference Include="System.Runtime" />
<Reference Include="System.Runtime.InteropServices" />
<Reference Include="System.Threading" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Collections\src\System.Collections.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Collections.Concurrent\src\System.Collections.Concurrent.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Linq\src\System.Linq.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Linq.Expressions\src\System.Linq.Expressions.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Memory\src\System.Memory.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.ObjectModel\src\System.ObjectModel.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime\src\System.Runtime.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\src\System.Runtime.InteropServices.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Threading\src\System.Threading.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(EnableComBinder)'=='true'">
<ProjectReference Include="$(LibrariesProjectRoot)System.Reflection.Emit\src\System.Reflection.Emit.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Reflection.Emit.ILGeneration\src\System.Reflection.Emit.ILGeneration.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Reflection.Emit.Lightweight\src\System.Reflection.Emit.Lightweight.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Reflection.Primitives\src\System.Reflection.Primitives.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)</TargetFrameworks>
<NoVbRuntimeReference>true</NoVbRuntimeReference>
<VBRuntime>None</VBRuntime>
<OptionStrict>On</OptionStrict>
<OptionExplicit>On</OptionExplicit>
<OptionInfer>Off</OptionInfer>
<MyType>Empty</MyType>
<OptionCompare>Binary</OptionCompare>
<WarningsNotAsErrors>42025</WarningsNotAsErrors>
<WarningsNotAsErrors>$(WarningsNotAsErrors),42025</WarningsNotAsErrors>
<DefineConstants>$(DefineConstants),LATEBINDING=True</DefineConstants>
<NoWarn>$(NoWarn),CA1052,CA1510,CA1810,CA1822,CA2200</NoWarn>
<!-- Avoid unused fields warnings in Unix build -->
<AssemblyName>Microsoft.VisualBasic.Core</AssemblyName>
<RemoveIntegerChecks>false</RemoveIntegerChecks>
<RootNamespace />
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppCurrent)-windows</TargetFrameworks>
<Nullable>disable</Nullable>
<UseCompilerGeneratedDocXmlFile>false</UseCompilerGeneratedDocXmlFile>
</PropertyGroup>

<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
<PropertyGroup>
<TargetPlatformIdentifier>$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))</TargetPlatformIdentifier>
<ILLinkDescriptorsXml Condition="'$(TargetPlatformIdentifier)' == 'windows'">$(MSBuildProjectDirectory)\ILLink\ILLink.Descriptors.Windows.xml</ILLinkDescriptorsXml>
<DefineConstants Condition="'$(TargetPlatformIdentifier)' == 'windows'">$(DefineConstants),TARGET_WINDOWS=True</DefineConstants>
<NoWarn Condition="'$(TargetPlatformIdentifier)' != 'windows'">$(NoWarn);CA1823</NoWarn>
</PropertyGroup>

<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'windows'">
<Compile Include="Microsoft\VisualBasic\Helpers\NativeMethods.vb" />
<Compile Include="Microsoft\VisualBasic\Helpers\NativeTypes.vb" />
<Compile Include="Microsoft\VisualBasic\Helpers\SafeNativeMethods.vb" />
<Compile Include="Microsoft\VisualBasic\Helpers\UnsafeNativeMethods.vb" />
</ItemGroup>

<ItemGroup>
<Compile Include="Microsoft\VisualBasic\Collection.vb" />
<Compile Include="Microsoft\VisualBasic\ComClassAttribute.vb" />
Expand Down Expand Up @@ -100,25 +104,27 @@
<Compile Include="Microsoft\VisualBasic\VBFixedStringAttribute.vb" />
<Compile Include="Microsoft\VisualBasic\VBMath.vb" />
</ItemGroup>

<ItemGroup>
<Reference Include="Microsoft.Win32.Primitives" />
<Reference Include="Microsoft.Win32.Registry" />
<Reference Include="System.Collections" />
<Reference Include="System.Collections.NonGeneric" />
<Reference Include="System.Collections.Specialized" />
<Reference Include="System.ComponentModel.Primitives" />
<Reference Include="System.Diagnostics.Process" />
<Reference Include="System.IO.FileSystem.DriveInfo" />
<Reference Include="System.Linq" />
<Reference Include="System.Linq.Expressions" />
<Reference Include="System.ObjectModel" />
<Reference Include="System.Reflection.Emit.ILGeneration" />
<Reference Include="System.Reflection.Emit.Lightweight" />
<Reference Include="System.Reflection.Primitives" />
<Reference Include="System.Runtime" />
<Reference Include="System.Runtime.InteropServices" />
<Reference Include="System.Text.RegularExpressions" />
<Reference Include="System.Threading" />
<Reference Include="System.Threading.Thread" />
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Win32.Primitives\src\Microsoft.Win32.Primitives.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Win32.Registry\src\Microsoft.Win32.Registry.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Collections.NonGeneric\src\System.Collections.NonGeneric.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Collections.Specialized\src\System.Collections.Specialized.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Collections\src\System.Collections.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.ComponentModel.Primitives\src\System.ComponentModel.Primitives.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Diagnostics.Process\src\System.Diagnostics.Process.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.IO.FileSystem.DriveInfo\src\System.IO.FileSystem.DriveInfo.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Linq.Expressions\src\System.Linq.Expressions.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Linq\src\System.Linq.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.ObjectModel\src\System.ObjectModel.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Reflection.Emit.ILGeneration\src\System.Reflection.Emit.ILGeneration.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Reflection.Emit.Lightweight\src\System.Reflection.Emit.Lightweight.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Reflection.Primitives\src\System.Reflection.Primitives.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\src\System.Runtime.InteropServices.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime\src\System.Runtime.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Text.RegularExpressions\src\System.Text.RegularExpressions.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Threading.Thread\src\System.Threading.Thread.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Threading\src\System.Threading.csproj" />
</ItemGroup>

</Project>
Loading
Loading