diff options
Diffstat (limited to 'src/Directory.Build.targets')
| -rw-r--r-- | src/Directory.Build.targets | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/Directory.Build.targets b/src/Directory.Build.targets new file mode 100644 index 00000000..48629385 --- /dev/null +++ b/src/Directory.Build.targets | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | <?xml version="1.0" encoding="utf-8"?> | ||
| 2 | <!-- | ||
| 3 | Replace PackageReferences with ProjectReferences when the projects can be found in .sln. | ||
| 4 | See the original here: https://github.com/dotnet/sdk/issues/1151#issuecomment-385133284 | ||
| 5 | --> | ||
| 6 | <Project> | ||
| 7 | <PropertyGroup> | ||
| 8 | <ReplacePackageReferences>true</ReplacePackageReferences> | ||
| 9 | <TheSolutionPath Condition=" '$(NCrunch)'=='' ">$(SolutionPath)</TheSolutionPath> | ||
| 10 | <TheSolutionPath Condition=" '$(NCrunch)'=='1' ">$(NCrunchOriginalSolutionPath)</TheSolutionPath> | ||
| 11 | </PropertyGroup> | ||
| 12 | |||
| 13 | <Choose> | ||
| 14 | <When Condition="$(ReplacePackageReferences) AND '$(TheSolutionPath)' != '' AND '$(TheSolutionPath)' != '*undefined*' AND Exists('$(TheSolutionPath)')"> | ||
| 15 | |||
| 16 | <PropertyGroup> | ||
| 17 | <SolutionFileContent>$([System.IO.File]::ReadAllText($(TheSolutionPath)))</SolutionFileContent> | ||
| 18 | <SmartSolutionDir>$([System.IO.Path]::GetDirectoryName( $(TheSolutionPath) ))</SmartSolutionDir> | ||
| 19 | <RegexPattern>(?<="[PackageName]", ")(.*)(?=", ")</RegexPattern> | ||
| 20 | </PropertyGroup> | ||
| 21 | |||
| 22 | <ItemGroup> | ||
| 23 | <!-- Keep the identity of the PackageReference --> | ||
| 24 | <SmartPackageReference Include="@(PackageReference)"> | ||
| 25 | <PackageName>%(Identity)</PackageName> | ||
| 26 | <InSolution>$(SolutionFileContent.Contains('\%(Identity).csproj'))</InSolution> | ||
| 27 | </SmartPackageReference> | ||
| 28 | |||
| 29 | <!-- Filter them by mapping them to another ItemGroup using the WithMetadataValue item function --> | ||
| 30 | <PackageInSolution Include="@(SmartPackageReference->WithMetadataValue('InSolution', True))"> | ||
| 31 | <Pattern>$(RegexPattern.Replace('[PackageName]','%(PackageName)') )</Pattern> | ||
| 32 | <SmartPath>$([System.Text.RegularExpressions.Regex]::Match('$(SolutionFileContent)', '%(Pattern)'))</SmartPath> | ||
| 33 | </PackageInSolution> | ||
| 34 | |||
| 35 | <ProjectReference Include="@(PackageInSolution->'$(SmartSolutionDir)\%(SmartPath)' )"/> | ||
| 36 | |||
| 37 | <!-- Remove the package references that are now referenced as projects --> | ||
| 38 | <PackageReference Remove="@(PackageInSolution->'%(PackageName)' )"/> | ||
| 39 | </ItemGroup> | ||
| 40 | |||
| 41 | </When> | ||
| 42 | </Choose> | ||
| 43 | </Project> | ||
