Skip to content

Commit 8ed08ab

Browse files
twsouthwickStephenMolloy
authored andcommitted
Make RoslynToolPath a dynamic property so copy occurs on restore (#87)
* Make RoslynToolPath a dynamic property so copy occurs on restore RoslynToolPath (and subsequently the list of roslyn files to copy) was calculated once since it was done outside of a target. By moving it into a target, it will be recalculated on each invocation. This also updates the DependsOnTarget attributes to ensure calculation is done when needed. This change also removes the install.ps1/uninstall.ps1 since those are no longer needed. * Add ps1 files back * Add comment for ps1 files
1 parent 91074aa commit 8ed08ab

8 files changed

Lines changed: 59 additions & 25 deletions

src/Packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/build/Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props renamed to src/Packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/build/Microsoft.CodeDom.Providers.DotNetCompilerPlatform.targets

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2-
<Import Project="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Extensions.props"/>
2+
<Import Project="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Extensions.targets"/>
33

4-
<ItemGroup>
5-
<RoslynCompilerFiles Include="$(RoslynToolPath)\*">
6-
<Link>roslyn\%(RecursiveDir)%(Filename)%(Extension)</Link>
7-
</RoslynCompilerFiles>
8-
</ItemGroup>
9-
<Target Name="IncludeRoslynCompilerFilesToFilesForPackagingFromProject" BeforeTargets="PipelineCollectFilesPhase" >
4+
<Target Name="SetRoslynCompilerFiles" DependsOnTargets="LocateRoslynCompilerFiles">
5+
<Message Text="Using Roslyn from '$(RoslynToolPath)' folder" />
6+
<ItemGroup>
7+
<RoslynCompilerFiles Include="$(RoslynToolPath)\*">
8+
<Link>roslyn\%(RecursiveDir)%(Filename)%(Extension)</Link>
9+
</RoslynCompilerFiles>
10+
</ItemGroup>
11+
</Target>
12+
13+
<Target Name="IncludeRoslynCompilerFilesToFilesForPackagingFromProject" BeforeTargets="PipelineCollectFilesPhase" DependsOnTargets="SetRoslynCompilerFiles" >
1014
<ItemGroup>
1115
<FilesForPackagingFromProject Include="@(RoslynCompilerFiles)">
1216
<DestinationRelativePath>bin\roslyn\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
@@ -15,29 +19,35 @@
1519
</FilesForPackagingFromProject>
1620
</ItemGroup>
1721
</Target>
22+
1823
<Target Name="LocateRoslynToolsDestinationFolder" Condition=" '$(RoslynToolsDestinationFolder)' == '' ">
19-
<PropertyGroup>
20-
<RoslynToolsDestinationFolder>$(WebProjectOutputDir)\bin\roslyn</RoslynToolsDestinationFolder>
21-
<RoslynToolsDestinationFolder Condition=" '$(WebProjectOutputDir)' == '' ">$(OutputPath)\roslyn</RoslynToolsDestinationFolder>
24+
<PropertyGroup>
25+
<RoslynToolsDestinationFolder>$(WebProjectOutputDir)\bin\roslyn</RoslynToolsDestinationFolder>
26+
<RoslynToolsDestinationFolder Condition=" '$(WebProjectOutputDir)' == '' ">$(OutputPath)\roslyn</RoslynToolsDestinationFolder>
2227
</PropertyGroup>
2328
</Target>
24-
<Target Name="CopyRoslynCompilerFilesToOutputDirectory" AfterTargets="CopyFilesToOutputDirectory" DependsOnTargets="LocateRoslynToolsDestinationFolder">
29+
30+
<Target Name="CopyRoslynCompilerFilesToOutputDirectory" AfterTargets="CopyFilesToOutputDirectory" DependsOnTargets="LocateRoslynToolsDestinationFolder;SetRoslynCompilerFiles">
2531
<Copy SourceFiles="@(RoslynCompilerFiles)" DestinationFolder="$(RoslynToolsDestinationFolder)" ContinueOnError="true" SkipUnchangedFiles="true" Retries="0" />
2632
<ItemGroup Condition="'$(MSBuildLastTaskResult)' == 'True'" >
2733
<FileWrites Include="$(RoslynToolsDestinationFolder)\*" />
2834
</ItemGroup>
2935
</Target>
30-
<Target Name="CheckIfShouldKillVBCSCompiler">
36+
37+
<Target Name="CheckIfShouldKillVBCSCompiler" DependsOnTargets="LocateRoslynCompilerFiles;LocateRoslynToolsDestinationFolder">
3138
<CheckIfVBCSCompilerWillOverride src="$(RoslynToolPath)\VBCSCompiler.exe" dest="$(RoslynToolsDestinationFolder)\VBCSCompiler.exe">
3239
<Output TaskParameter="WillOverride" PropertyName="ShouldKillVBCSCompiler" />
3340
</CheckIfVBCSCompilerWillOverride>
3441
</Target>
35-
<Target Name = "KillVBCSCompilerBeforeCopy" BeforeTargets="CopyRoslynCompilerFilesToOutputDirectory" DependsOnTargets="LocateRoslynToolsDestinationFolder;CheckIfShouldKillVBCSCompiler" >
42+
43+
<Target Name="KillVBCSCompilerBeforeCopy" BeforeTargets="CopyRoslynCompilerFilesToOutputDirectory" DependsOnTargets="LocateRoslynToolsDestinationFolder;CheckIfShouldKillVBCSCompiler" >
3644
<KillProcess ProcessName="VBCSCompiler" ImagePath="$(RoslynToolsDestinationFolder)" Condition="'$(ShouldKillVBCSCompiler)' == 'True'" />
3745
</Target>
38-
<Target Name = "KillVBCSCompilerBeforeClean" AfterTargets="BeforeClean" DependsOnTargets="LocateRoslynToolsDestinationFolder">
46+
47+
<Target Name="KillVBCSCompilerBeforeClean" AfterTargets="BeforeClean" DependsOnTargets="LocateRoslynToolsDestinationFolder">
3948
<KillProcess ProcessName="VBCSCompiler" ImagePath="$(RoslynToolsDestinationFolder)" />
4049
</Target>
50+
4151
<UsingTask TaskName="KillProcess" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
4252
<ParameterGroup>
4353
<ProcessName ParameterType="System.String" Required="true" />
@@ -89,6 +99,7 @@
8999
</Code>
90100
</Task>
91101
</UsingTask>
102+
92103
<UsingTask TaskName="CheckIfVBCSCompilerWillOverride" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
93104
<ParameterGroup>
94105
<Src ParameterType="System.String" Required="true" />
@@ -102,7 +113,7 @@
102113
WillOverride = false;
103114
try {
104115
WillOverride = File.Exists(Src) && File.Exists(Dest) && (File.GetLastWriteTime(Src) != File.GetLastWriteTime(Dest));
105-
}
116+
}
106117
catch { }
107118
]]>
108119
</Code>

src/Packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/build/net45/Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Extensions.props

Lines changed: 0 additions & 5 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
3+
<Target Name="LocateRoslynCompilerFiles">
4+
<PropertyGroup>
5+
<RoslynToolPath Condition="'$(RoslynToolPath)' == ''">$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\..\tools\roslyn45'))</RoslynToolPath>
6+
</PropertyGroup>
7+
</Target>
8+
9+
</Project>

src/Packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/build/net46/Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Extensions.props

Lines changed: 0 additions & 5 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
3+
<Target Name="LocateRoslynCompilerFiles">
4+
<PropertyGroup>
5+
<RoslynToolPath Condition="'$(RoslynToolPath)' == ''">$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\..\tools\roslynlatest'))</RoslynToolPath>
6+
</PropertyGroup>
7+
</Target>
8+
9+
</Project>

src/Packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/tools/install.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Copyright (c) .NET Foundation. All rights reserved.
22
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
#####################################################################################################
5+
## Although the NuGet package includes msbuild targets that does this same work, the ps1 files are #
6+
## kept for use in web site projects #
7+
#####################################################################################################
8+
49
param($installPath, $toolsPath, $package, $project)
510

611
$roslynSubFolder = 'roslyn'

src/Packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/tools/uninstall.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Copyright (c) .NET Foundation. All rights reserved.
22
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
#####################################################################################################
5+
## Although the NuGet package includes msbuild targets that does this same work, the ps1 files are #
6+
## kept for use in web site projects #
7+
#####################################################################################################
8+
49
param($installPath, $toolsPath, $package, $project)
510

611
$roslynSubFolder = 'roslyn'

src/Packages/Packages.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
<None Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform\tools\install.ps1" />
3737
<None Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform\tools\uninstall.ps1" />
3838
</ItemGroup>
39+
<ItemGroup>
40+
<None Include="**\*.targets" />
41+
<None Include="**\*.xdt" />
42+
<None Include="**\*.nuspec" />
43+
</ItemGroup>
3944
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
4045
<Target Name="Build">
4146
<MSBuild Projects="@(NuGetProject)" Targets="Build" />

0 commit comments

Comments
 (0)