Integrate SmartPackageReference
Rob Mensching committed
Dec 22, 2018 at 08:14 UTC
d9a6764a268a07ea159c39a8799e9bdf6efffb24
2 files changed
+44
-5
src/Directory.Build.props
+1
-5
@@ -10,7 +10,7 @@
10
<EnableSourceLink Condition=" '$(NCrunch)' == '1' ">false</EnableSourceLink>
11
12
<ProjectName Condition=" '$(ProjectName)' == '' ">$(MSBuildProjectName)</ProjectName>
13
- <BaseOutputPath>$(MSBuildThisFileDirectory)..\build\</BaseOutputPath>
13
+ <BaseOutputPath>$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)..\build\))</BaseOutputPath>
14
<BaseIntermediateOutputPath>$(BaseOutputPath)obj\$(ProjectName)\</BaseIntermediateOutputPath>
15
<OutputPath>$(BaseOutputPath)$(Configuration)\</OutputPath>
16
@@ -20,10 +20,6 @@
20
<Product>WiX Toolset</Product>
21
</PropertyGroup>
22
23
- <PropertyGroup>
24
- <WixToolsetRootFolder>$(MSBuildThisFileDirectory)..\..\</WixToolsetRootFolder>
25
- </PropertyGroup>
26
-
23
<Import Project="Cpp.Build.props" Condition=" '$(MSBuildProjectExtension)'=='.vcxproj' " />
24
<Import Project="Custom.Build.props" Condition=" Exists('Custom.Build.props') " />
25
</Project>
src/Directory.Build.targets
new
+43
@@ -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>