Skip to content

Commit 8cba211

Browse files
authored
Updates to TFM support for reference pkg src generator
2 parents 4a1eff2 + ae9d526 commit 8cba211

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

src/referencePackageSourceGenerator/ReferencePackageProjectTemplate.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>$$TargetFrameworks$$</TargetFrameworks>
5-
<NuspecFile>$(ArtifactsBinDir)$$RelativePath$$/$$LowerCaseFileName$$.nuspec</NuspecFile>$$KeyFileTag$$$$EnableImplicitReferencesTag$$
5+
<NuspecFile>$(ArtifactsBinDir)$$RelativePath$$/$$LowerCaseFileName$$.nuspec</NuspecFile>$$KeyFileTag$$
66
</PropertyGroup>
77

88
<PropertyGroup>
99
<OutputPath>$(ArtifactsBinDir)$$RelativePath$$/ref/</OutputPath>
1010
<IntermediateOutputPath>$(ArtifactsObjDir)$$RelativePath$$</IntermediateOutputPath>
1111
</PropertyGroup>
12-
$$OutputPathByTfm$$ <ItemGroup>
12+
$$TfmSpecificProperties$$ <ItemGroup>
1313
<Compile Include="**/ref/$(TargetFramework)/*.cs" />
1414
<Compile Include="**/lib/$(TargetFramework)/*.cs" />
1515
</ItemGroup>

src/referencePackageSourceGenerator/ReferencePackageSourceGenerator.proj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
<!-- The following target frameworks aren't buildable with the current SDK and as they don't contribute to the set of
99
source build target verticals, can be safely excluded. -->
1010
<ExcludeTargetFrameworks>netcore50;net463;portable-*;xamarin*;monotouch*;monoandroid*;win8;wp8;wpa81</ExcludeTargetFrameworks>
11+
<!-- The following target frameworks should be excluded even though they are supported by the current SDK because there is no need to have them.
12+
Only exclude them when target frameworks to include aren't provided. -->
13+
<ExcludeTargetFrameworks Condition="'$(IncludeTargetFrameworks)' == ''">$(ExcludeTargetFrameworks);netcoreapp3.1</ExcludeTargetFrameworks>
1114
</PropertyGroup>
1215

1316
<PropertyGroup Condition="'$(PackageName)' != '' and '$(PackageVersion)' != ''">

src/referencePackageSourceGenerator/ReferencePackageSourceTask/GenerateProject.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public override bool Execute()
4040
string projectTemplateContent = File.ReadAllText(ProjectTemplate);
4141
string pkgProjectOutput = projectTemplateContent;
4242
string packageReferenceIncludes = "\n";
43-
string outputPathByTfm = "\n";
43+
string tfmSpecificProperties = "\n";
4444

4545
// Make sure that we always use the same directory separator.
4646
string relativePath = Path.GetRelativePath(BaseTargetPath, Path.GetDirectoryName(TargetPath)).Replace('\\', '/');
@@ -55,7 +55,7 @@ public override bool Execute()
5555
string packageReferences = "";
5656
string netStandardTag = "NETStandardImplicitPackageVersion";
5757

58-
if (targetFramework == "netstandard2.0" && !includesNetStandard21 && !includesNetCoreApp30)
58+
if (targetFramework == "netstandard2.0")
5959
{
6060
packageReferences += $" <PackageReference Include=\"NETStandard.Library\" Version=\"$({netStandardTag})\" />\n";
6161
}
@@ -135,12 +135,18 @@ public override bool Execute()
135135
}
136136
}
137137

138+
tfmSpecificProperties += $" <PropertyGroup Condition=\" '$(TargetFramework)' == '{targetFramework}' \">\n";
138139
if (subPath == "lib")
139140
{
140-
outputPathByTfm += $" <PropertyGroup Condition=\" '$(TargetFramework)' == '{targetFramework}' \">\n";
141-
outputPathByTfm += $" <OutputPath>$(ArtifactsBinDir){relativePath}/{subPath}/</OutputPath>\n";
142-
outputPathByTfm += $" </PropertyGroup>\n\n";
141+
tfmSpecificProperties += $" <OutputPath>$(ArtifactsBinDir){relativePath}/{subPath}/</OutputPath>\n";
143142
}
143+
if (targetFramework == "netstandard2.1" ||
144+
targetFramework == "netcoreapp3.0" ||
145+
targetFramework == "net6.0")
146+
{
147+
tfmSpecificProperties += " <DisableImplicitFrameworkReferences>false</DisableImplicitFrameworkReferences>\n";
148+
}
149+
tfmSpecificProperties += $" </PropertyGroup>\n\n";
144150
}
145151

146152
// If necessary, write the strong name key into the project file.
@@ -151,19 +157,12 @@ public override bool Execute()
151157
keyFileTag = $"\n <StrongNameKeyId>{strongNameData.Id}</StrongNameKeyId>";
152158
}
153159

154-
string enableImplicitReferencesTag = "";
155-
if (includesNetStandard21 || includesNetCoreApp30)
156-
{
157-
enableImplicitReferencesTag = "\n <DisableImplicitFrameworkReferences>false</DisableImplicitFrameworkReferences>";
158-
}
159-
160160
pkgProjectOutput = pkgProjectOutput.Replace("$$LowerCaseFileName$$", PackageId.ToLowerInvariant());
161-
pkgProjectOutput = pkgProjectOutput.Replace("$$OutputPathByTfm$$", outputPathByTfm);
161+
pkgProjectOutput = pkgProjectOutput.Replace("$$TfmSpecificProperties$$", tfmSpecificProperties);
162162
pkgProjectOutput = pkgProjectOutput.Replace("$$RelativePath$$", relativePath);
163163
pkgProjectOutput = pkgProjectOutput.Replace("$$PackageReferences$$", packageReferenceIncludes);
164164
pkgProjectOutput = pkgProjectOutput.Replace("$$TargetFrameworks$$", string.Join(';', orderedTargetFrameworks));
165165
pkgProjectOutput = pkgProjectOutput.Replace("$$KeyFileTag$$", keyFileTag);
166-
pkgProjectOutput = pkgProjectOutput.Replace("$$EnableImplicitReferencesTag$$", enableImplicitReferencesTag);
167166

168167
// Generate the project file
169168
Directory.CreateDirectory(Path.GetDirectoryName(TargetPath));

0 commit comments

Comments
 (0)