Skip to content

Commit 9b3501d

Browse files
authored
Use ImplicitFrameworkReferences & update GenAPI & update docs (#572)
1 parent 8cba211 commit 9b3501d

File tree

8 files changed

+59
-58
lines changed

8 files changed

+59
-58
lines changed

README.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ After generating new reference packages, all new projects must be referenced as
4646
These must be defined in dependency order. There is a [tracking issue](https://github.com/dotnet/source-build/issues/1690)
4747
to address this manual step.
4848

49-
The tooling will not pull in icons referenced by the nuspec so they will have to be manually removed. There is a
50-
[tracking issue](https://github.com/dotnet/source-build/issues/1957) to address this manual step.
51-
5249
The tooling does not handle all situations and sometimes the generated code will need manual tweeks to get it to compile.
5350
If this occurs when generating a newer version of an existing package, it can be helpful to regenerate the older version
5451
to see what changes were made.
@@ -64,7 +61,7 @@ when it was originally generated.
6461
* Run build with the `./build.sh -sb` command.
6562
* If the compilation produces numerous compilation issue - run the `./build.sh --projects <path to .csproj file>` command for each generated reference package separately.
6663

67-
You can search for known issues in the `docs/known_generator_issues.md`.
64+
You can search for known issues in the [Known Generator Issues Markdown file](docs/known_generator_issues.md).
6865

6966
### Targeting
7067

docs/known_generator_issues.md

-17
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
11
# Known issues
22

3-
## Unsupported `netcoreapp3.1` TFM
4-
5-
Tracking [issue](https://github.com/dotnet/source-build/issues/3251)
6-
7-
Reference packages for TFM `netcoreapp3.1` are not supported. You may get numerous compilation issues like:
8-
9-
```text
10-
*/lib/netcoreapp3.1/*: error CS0246: The type or namespace name 'DebuggableAttribute' could not be found
11-
*/lib/netcoreapp3.1/*: error CS0518: Predefined type 'System.String' is not defined or imported
12-
```
13-
14-
Workaround: update the `*.csproj` file:
15-
16-
* remove the `netcoreapp3.1` TFM from the `<TargetFrameworks>` list.
17-
* remove `<PropertyGroup>` and `<ItemGroup>` with the `netcoreapp3.1` condition.
18-
* remove the `lib\netcoreapp3.1` folder.
19-
203
## The explicit declaration of `TupleElementNamesAttribute` attribute
214

225
```text

eng/Version.Details.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
<Sha>cb64095ec45ac34378a1a26db9932a3b561f9e4e</Sha>
1212
<SourceBuild RepoName="arcade" ManagedOnly="true" />
1313
</Dependency>
14-
<Dependency Name="Microsoft.DotNet.GenAPI.Task" Version="8.0.100-preview.3.23162.7">
14+
<Dependency Name="Microsoft.DotNet.GenAPI.Task" Version="8.0.100-preview.3.23164.38">
1515
<Uri>https://github.com/dotnet/sdk</Uri>
16-
<Sha>04c86729462625b60304075962ac201a0d93a133</Sha>
16+
<Sha>83971ae73e9a40583d4648ab746e0c44bd03572d</Sha>
1717
</Dependency>
1818
<Dependency Name="Microsoft.SourceLink.GitHub" Version="1.2.0-beta-23151-02" CoherentParentDependency="Microsoft.DotNet.Arcade.Sdk">
1919
<Uri>https://github.com/dotnet/sourcelink</Uri>

eng/Versions.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
<MicrosoftNETCoreILAsmVersion>6.0.0-preview.6.21352.12</MicrosoftNETCoreILAsmVersion>
2121
<MicrosoftNETCoreILDAsmVersion>6.0.0-preview.6.21352.12</MicrosoftNETCoreILDAsmVersion>
2222
<!-- SDK dependencies -->
23-
<MicrosoftDotNetGenAPITaskPackageVersion>8.0.100-preview.3.23162.7</MicrosoftDotNetGenAPITaskPackageVersion>
23+
<MicrosoftDotNetGenAPITaskPackageVersion>8.0.100-preview.3.23164.38</MicrosoftDotNetGenAPITaskPackageVersion>
2424
</PropertyGroup>
2525
</Project>

src/referencePackageSourceGenerator/ReferencePackageProjectTemplate.xml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>$$TargetFrameworks$$</TargetFrameworks>
5+
<DisableImplicitFrameworkReferences>false</DisableImplicitFrameworkReferences>
56
<NuspecFile>$(ArtifactsBinDir)$$RelativePath$$/$$LowerCaseFileName$$.nuspec</NuspecFile>$$KeyFileTag$$
67
</PropertyGroup>
78

src/referencePackageSourceGenerator/ReferencePackageSourceTask/GenerateProject.cs

+3-32
Original file line numberDiff line numberDiff line change
@@ -45,43 +45,20 @@ public override bool Execute()
4545
// Make sure that we always use the same directory separator.
4646
string relativePath = Path.GetRelativePath(BaseTargetPath, Path.GetDirectoryName(TargetPath)).Replace('\\', '/');
4747
StrongNameData strongNameData = default;
48-
49-
bool includesNetStandard21 = TargetFrameworks.Contains("netstandard2.1");
50-
bool includesNetCoreApp30 = TargetFrameworks.Contains("netcoreapp3.0");
5148
string[] orderedTargetFrameworks = TargetFrameworks.Order().ToArray();
5249

5350
foreach (string targetFramework in orderedTargetFrameworks)
5451
{
5552
string packageReferences = "";
56-
string netStandardTag = "NETStandardImplicitPackageVersion";
57-
58-
if (targetFramework == "netstandard2.0")
59-
{
60-
packageReferences += $" <PackageReference Include=\"NETStandard.Library\" Version=\"$({netStandardTag})\" />\n";
61-
}
6253

6354
// Add package dependencies
6455
foreach (ITaskItem packageDependency in PackageDependencies.Where(packageDependency => packageDependency.GetMetadata("TargetFramework") == targetFramework))
6556
{
66-
// TODO: Generate a lookup table from source-build/PackageVersions.props. For now, there is only one...
57+
// Don't emit package references for targeting packs as those are added implicitly by the SDK.
6758
if (packageDependency.ItemSpec == "NETStandard.Library")
68-
{
69-
if (!includesNetStandard21 && !includesNetCoreApp30)
70-
{
71-
packageReferences += $" <PackageReference Include=\"{packageDependency.ItemSpec}\" Version=\"$({netStandardTag})\" />\n";
72-
}
73-
}
74-
else
75-
{
76-
string version = packageDependency.GetMetadata("Version");
77-
packageReferences += $" <PackageReference Include=\"{packageDependency.ItemSpec}\" Version=\"{version}\" />\n";
78-
}
79-
}
59+
continue;
8060

81-
// Add .NET Framework targeting pack reference
82-
if (targetFramework.StartsWith("net4"))
83-
{
84-
packageReferences += $" <PackageReference Include=\"Microsoft.NETFramework.ReferenceAssemblies.{targetFramework}\" Version=\"1.0.2\" />\n";
61+
packageReferences += $" <PackageReference Include=\"{packageDependency.ItemSpec}\" Version=\"{packageDependency.GetMetadata("Version")}\" />\n";
8562
}
8663

8764
// Add framework references
@@ -140,12 +117,6 @@ public override bool Execute()
140117
{
141118
tfmSpecificProperties += $" <OutputPath>$(ArtifactsBinDir){relativePath}/{subPath}/</OutputPath>\n";
142119
}
143-
if (targetFramework == "netstandard2.1" ||
144-
targetFramework == "netcoreapp3.0" ||
145-
targetFramework == "net6.0")
146-
{
147-
tfmSpecificProperties += " <DisableImplicitFrameworkReferences>false</DisableImplicitFrameworkReferences>\n";
148-
}
149120
tfmSpecificProperties += $" </PropertyGroup>\n\n";
150121
}
151122

src/referencePackages/Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<AssemblyName Condition="'$(AssemblyName)' == ''">$([MSBuild]::MakeRelative('$(MSBuildThisFileDirectory)src', '$(ProjectParentDir)'))</AssemblyName>
1515
</PropertyGroup>
1616

17-
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props, $(MSBuildThisFileDirectory)..))" />
17+
<Import Project="..\Directory.Build.props" />
1818

1919
<PropertyGroup>
2020
<!-- Common properties for all Reference Packages -->
+50-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,53 @@
11
<Project>
22

3-
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets, $(MSBuildThisFileDirectory)..))" />
3+
<Import Project="..\Directory.Build.targets" />
4+
5+
<!--
6+
### Targeting Packs section ###
7+
Keep in sync with available targeting packs under src/targetPacks/ILsrc.
8+
-->
9+
10+
<PropertyGroup>
11+
<MicrosoftNETFrameworkReferenceAssembliesLatestPackageVersion>1.0.2</MicrosoftNETFrameworkReferenceAssembliesLatestPackageVersion>
12+
<!-- The SDK already sets the NETStandardImplicitPackageVersion and we don't expect it to change anymore. Hence, we don't encode it here. -->
13+
</PropertyGroup>
14+
15+
<ItemGroup>
16+
<KnownFrameworkReference Update="@(KnownFrameworkReference->WithMetadataValue('Identity', 'Microsoft.NETCore.App'))">
17+
<TargetingPackVersion Condition="'%(TargetFramework)' == 'netcoreapp3.0'">3.0.0</TargetingPackVersion>
18+
<TargetingPackVersion Condition="'%(TargetFramework)' == 'netcoreapp3.1'">3.1.0</TargetingPackVersion>
19+
<TargetingPackVersion Condition="'%(TargetFramework)' == 'net5.0'">5.0.0</TargetingPackVersion>
20+
<TargetingPackVersion Condition="'%(TargetFramework)' == 'net6.0'">6.0.0</TargetingPackVersion>
21+
</KnownFrameworkReference>
22+
23+
<KnownFrameworkReference Update="@(KnownFrameworkReference->WithMetadataValue('Identity', 'Microsoft.AspNetCore.App'))">
24+
<TargetingPackVersion Condition="'%(TargetFramework)' == 'netcoreapp3.0'">3.0.1</TargetingPackVersion>
25+
<TargetingPackVersion Condition="'%(TargetFramework)' == 'netcoreapp3.1'">3.1.10</TargetingPackVersion>
26+
</KnownFrameworkReference>
27+
28+
<KnownFrameworkReference Update="@(KnownFrameworkReference->WithMetadataValue('Identity', 'NETStandard.Library'))">
29+
<TargetingPackVersion Condition="'%(TargetFramework)' == 'netstandard2.1'">2.1.0</TargetingPackVersion>
30+
</KnownFrameworkReference>
31+
</ItemGroup>
32+
33+
<!-- Filter out conflicting implicit assembly references. -->
34+
<Target Name="FilterImplicitAssemblyReferences"
35+
Condition="'$(DisableImplicitFrameworkReferences)' != 'true'"
36+
DependsOnTargets="ResolveProjectReferences"
37+
AfterTargets="ResolveTargetingPackAssets">
38+
<ItemGroup>
39+
<_targetingPackReferenceExclusion Include="$(TargetName)" />
40+
<_targetingPackReferenceExclusion Include="@(_ResolvedProjectReferencePaths->Metadata('Filename'))" />
41+
</ItemGroup>
42+
<ItemGroup>
43+
<_targetingPackReferenceWithProjectName Include="@(Reference->WithMetadataValue('ExternallyResolved', 'true')->Metadata('Filename'))"
44+
OriginalIdentity="%(Identity)" />
45+
<_targetingPackIncludedReferenceWithProjectName Include="@(_targetingPackReferenceWithProjectName)"
46+
Exclude="@(_targetingPackReferenceExclusion)" />
47+
<_targetingPackExcludedReferenceWithProjectName Include="@(_targetingPackReferenceWithProjectName)"
48+
Exclude="@(_targetingPackIncludedReferenceWithProjectName)" />
49+
<Reference Remove="@(_targetingPackExcludedReferenceWithProjectName->Metadata('OriginalIdentity'))" />
50+
</ItemGroup>
51+
</Target>
52+
453
</Project>

0 commit comments

Comments
 (0)