Skip to content

Commit be6dfe0

Browse files
Use a netstandard dll for build tasks instead of inline fragments. This will allow building SDK-style full framework projects with 'dotnet build.' (#92)
1 parent f78434c commit be6dfe0

8 files changed

Lines changed: 141 additions & 75 deletions

File tree

Build.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ REM set logOptions=/v:diag /flp:Summary;Verbosity=normal;LogFile=msbuild.log /fl
1515

1616
echo Please build from VS 2015(or newer version) Developer Command Prompt
1717

18-
%MSBUILDEXE% "%~dp0\RoslynCodeProvider.msbuild" /t:BuildAll %logOptions% /maxcpucount /nodeReuse:false %cfgOption%%*
18+
%MSBUILDEXE% "%~dp0\RoslynCodeProvider.msbuild" /t:Build %logOptions% /maxcpucount /nodeReuse:false %cfgOption%%*
1919
if %ERRORLEVEL% neq 0 goto BuildFail
2020
goto BuildSuccess
2121

RoslynCodeProvider.msbuild

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@
33

44
<ItemGroup>
55
<AssemblyProject Include="src\Microsoft.CodeDom.Providers.DotNetCompilerPlatform\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.csproj" />
6+
<AssemblyProject Include="src\DotNetCompilerPlatformTasks\DotNetCompilerPlatformTasks.csproj" />
67
</ItemGroup>
8+
79
<ItemGroup>
8-
<AssemblyProject Include="RoslynCodeProviderTest\Microsoft.CodeDom.Providers.DotNetCompilerPlatformTest.csproj" />
10+
<PackageProject Include="src\Packages\Packages.csproj" />
911
</ItemGroup>
1012

1113
<ItemGroup>
12-
<PackageProject Include="src\Packages\Packages.csproj" />
14+
<TestProject Include="RoslynCodeProviderTest\Microsoft.CodeDom.Providers.DotNetCompilerPlatformTest.csproj" />
1315
</ItemGroup>
1416

17+
1518
<!-- Composite targets -->
1619
<Target Name="BuildCI" DependsOnTargets="Clean;Build" />
1720

18-
<Target Name="Build" DependsOnTargets="BuildAssemblies;BuildPackages" />
19-
<Target Name="Clean" DependsOnTargets="CleanPackages;CleanAssemblies" />
21+
<Target Name="Build" DependsOnTargets="BuildAssemblies;BuildTests;BuildPackages" />
22+
<Target Name="Clean" DependsOnTargets="CleanPackages;CleanTests;CleanAssemblies" />
2023
<Target Name="Rebuild" DependsOnTargets="Clean;Build" />
2124

2225
<!-- Core build-->
@@ -25,10 +28,18 @@
2528
<MSBuild Targets="Build" Projects="@(AssemblyProject)" />
2629
</Target>
2730

31+
<Target Name="BuildTests" DependsOnTargets="RestorePackages">
32+
<MSBuild Targets="Build" Projects="@(TestProject)" />
33+
</Target>
34+
2835
<Target Name="CleanAssemblies">
2936
<MSBuild Targets="Clean" Projects="@(AssemblyProject)" />
3037
</Target>
3138

39+
<Target Name="CleanTests">
40+
<MSBuild Targets="Clean" Projects="@(TestProject)" />
41+
</Target>
42+
3243
<Target Name="RebuildAssemblies" DependsOnTargets="Clean;Build" />
3344

3445
<!-- Packages build -->

RoslynCodeProvider.sln

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.CodeDom.Providers
1313
EndProject
1414
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Packages", "src\Packages\Packages.csproj", "{7EC5863F-7FF1-41C7-A384-8FFF81531E7A}"
1515
ProjectSection(ProjectDependencies) = postProject
16+
{E3D81E13-7489-4064-B789-AE1B02C7C616} = {E3D81E13-7489-4064-B789-AE1B02C7C616}
1617
{BE52ED6A-F180-499D-80BB-B0237B50023C} = {BE52ED6A-F180-499D-80BB-B0237B50023C}
1718
EndProjectSection
1819
EndProject
@@ -33,6 +34,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{6EB4E0
3334
.nuget\NuGet.targets = .nuget\NuGet.targets
3435
EndProjectSection
3536
EndProject
37+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetCompilerPlatformTasks", "src\DotNetCompilerPlatformTasks\DotNetCompilerPlatformTasks.csproj", "{E3D81E13-7489-4064-B789-AE1B02C7C616}"
38+
EndProject
3639
Global
3740
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3841
Debug|Any CPU = Debug|Any CPU
@@ -51,6 +54,10 @@ Global
5154
{7EC5863F-7FF1-41C7-A384-8FFF81531E7A}.Debug|Any CPU.Build.0 = Debug|Any CPU
5255
{7EC5863F-7FF1-41C7-A384-8FFF81531E7A}.Release|Any CPU.ActiveCfg = Release|Any CPU
5356
{7EC5863F-7FF1-41C7-A384-8FFF81531E7A}.Release|Any CPU.Build.0 = Release|Any CPU
57+
{E3D81E13-7489-4064-B789-AE1B02C7C616}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
58+
{E3D81E13-7489-4064-B789-AE1B02C7C616}.Debug|Any CPU.Build.0 = Debug|Any CPU
59+
{E3D81E13-7489-4064-B789-AE1B02C7C616}.Release|Any CPU.ActiveCfg = Release|Any CPU
60+
{E3D81E13-7489-4064-B789-AE1B02C7C616}.Release|Any CPU.Build.0 = Release|Any CPU
5461
EndGlobalSection
5562
GlobalSection(SolutionProperties) = preSolution
5663
HideSolutionNode = FALSE
@@ -59,6 +66,7 @@ Global
5966
{12B521BD-F065-4F81-BD7A-D6F715B38F12} = {770A45B7-BC65-4FC4-94FF-7F99838F3219}
6067
{BE52ED6A-F180-499D-80BB-B0237B50023C} = {566A9F52-15C9-4BD0-AD3A-9CC7D391834E}
6168
{7EC5863F-7FF1-41C7-A384-8FFF81531E7A} = {566A9F52-15C9-4BD0-AD3A-9CC7D391834E}
69+
{E3D81E13-7489-4064-B789-AE1B02C7C616} = {566A9F52-15C9-4BD0-AD3A-9CC7D391834E}
6270
EndGlobalSection
6371
GlobalSection(ExtensibilityGlobals) = postSolution
6472
SolutionGuid = {A5B8F404-C4DF-48B5-80FE-6FC256ADCEC3}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<PropertyGroup>
3+
<BaseIntermediateOutputPath>..\..\obj</BaseIntermediateOutputPath>
4+
<OutputPath>..\..\bin\$(Configuration)\</OutputPath>
5+
<OutDir>$(OutputPath)</OutDir>
6+
</PropertyGroup>
7+
</Project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
6+
</PropertyGroup>
7+
8+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
9+
</PropertyGroup>
10+
11+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
12+
</PropertyGroup>
13+
14+
<ItemGroup>
15+
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="14.3.0">
16+
<PrivateAssets>all</PrivateAssets>
17+
</PackageReference>
18+
<PackageReference Include="System.Management" Version="4.5.0" />
19+
</ItemGroup>
20+
21+
</Project>
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Management;
6+
using Microsoft.Build.Framework;
7+
using Microsoft.Build.Utilities;
8+
9+
namespace DotNetCompilerPlatformTasks
10+
{
11+
public class KillProcess : Task
12+
{
13+
[Required]
14+
public string ProcessName { get; set; }
15+
[Required]
16+
public string ImagePath { get; set; }
17+
18+
public override bool Execute()
19+
{
20+
try
21+
{
22+
foreach (var p in Process.GetProcessesByName(ProcessName))
23+
{
24+
var wmiQuery = "SELECT ProcessId, ExecutablePath FROM Win32_Process WHERE ProcessId = " + p.Id;
25+
using (var searcher = new ManagementObjectSearcher(wmiQuery))
26+
{
27+
using (var results = searcher.Get())
28+
{
29+
var mo = results.Cast<ManagementObject>().FirstOrDefault();
30+
if (mo != null)
31+
{
32+
var path = (string)mo["ExecutablePath"];
33+
var executablePath = path != null ? path : string.Empty;
34+
Log.LogMessage("ExecutablePath is {0}", executablePath);
35+
36+
if (executablePath.StartsWith(ImagePath, StringComparison.OrdinalIgnoreCase))
37+
{
38+
p.Kill();
39+
p.WaitForExit();
40+
Log.LogMessage("{0} is killed", executablePath);
41+
break;
42+
}
43+
}
44+
}
45+
}
46+
}
47+
}
48+
catch (Exception ex)
49+
{
50+
Log.LogWarning(ex.Message);
51+
}
52+
return true;
53+
}
54+
}
55+
56+
public class CheckIfVBCSCompilerWillOverride : Task
57+
{
58+
[Required]
59+
public string Src { get; set; }
60+
[Required]
61+
public string Dest { get; set; }
62+
63+
[Output]
64+
public bool WillOverride { get; set; }
65+
66+
public override bool Execute()
67+
{
68+
WillOverride = false;
69+
70+
try
71+
{
72+
WillOverride = File.Exists(Src) && File.Exists(Dest) && (File.GetLastWriteTime(Src) != File.GetLastWriteTime(Dest));
73+
}
74+
catch { return false; }
75+
76+
return true;
77+
}
78+
}
79+
}

src/Packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/Microsoft.CodeDom.Providers.DotNetCompilerPlatform.nuproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020
<Source>$(OutputPath)</Source>
2121
<Destination>lib\net45</Destination>
2222
</NuGetContent>
23+
<NuGetContent Include="DotNetCompilerPlatformTasks.dll">
24+
<Source>$(OutputPath)</Source>
25+
<Destination>tasks</Destination>
26+
</NuGetContent>
27+
<NuGetContent Include="System.Management.dll">
28+
<Source>$(OutputPath)</Source>
29+
<Destination>tasks</Destination>
30+
</NuGetContent>
2331
<NuGetContentProject Include="$(RepositoryRoot)\src\$(MSBuildProjectName)\$(MSBuildProjectName).csproj" Condition="'$(NuGetPackSymbols)' == 'true'" />
2432
<NuGetContent Include="Content\net45\*">
2533
<Destination>content\net45</Destination>

src/Packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/build/Microsoft.CodeDom.Providers.DotNetCompilerPlatform.targets

Lines changed: 2 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -48,75 +48,7 @@
4848
<KillProcess ProcessName="VBCSCompiler" ImagePath="$(RoslynToolsDestinationFolder)" />
4949
</Target>
5050

51-
<UsingTask TaskName="KillProcess" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
52-
<ParameterGroup>
53-
<ProcessName ParameterType="System.String" Required="true" />
54-
<ImagePath ParameterType="System.String" Required="true" />
55-
</ParameterGroup>
56-
<Task>
57-
<Reference Include="System" />
58-
<Reference Include="System.Management" />
59-
<Using Namespace="System" />
60-
<Using Namespace="System.Linq" />
61-
<Using Namespace="System.Diagnostics" />
62-
<Using Namespace="System.Management" />
63-
<Code Type="Fragment" Language="cs">
64-
<![CDATA[
65-
try
66-
{
67-
foreach(var p in Process.GetProcessesByName(ProcessName))
68-
{
69-
var wmiQuery = "SELECT ProcessId, ExecutablePath FROM Win32_Process WHERE ProcessId = " + p.Id;
70-
using(var searcher = new ManagementObjectSearcher(wmiQuery))
71-
{
72-
using(var results = searcher.Get())
73-
{
74-
var mo = results.Cast<ManagementObject>().FirstOrDefault();
75-
if(mo != null)
76-
{
77-
var path = (string)mo["ExecutablePath"];
78-
var executablePath = path != null ? path : string.Empty;
79-
Log.LogMessage("ExecutablePath is {0}", executablePath);
51+
<UsingTask TaskName="KillProcess" AssemblyFile="..\..\tasks\DotNetCompilerPlatformTasks.dll" />
52+
<UsingTask TaskName="CheckIfVBCSCompilerWillOverride" AssemblyFile="..\..\tasks\DotNetCompilerPlatformTasks.dll" />
8053

81-
if(executablePath.StartsWith(ImagePath, StringComparison.OrdinalIgnoreCase))
82-
{
83-
p.Kill();
84-
p.WaitForExit();
85-
Log.LogMessage("{0} is killed", executablePath);
86-
break;
87-
}
88-
}
89-
}
90-
}
91-
}
92-
}
93-
catch (Exception ex)
94-
{
95-
Log.LogWarning(ex.Message);
96-
}
97-
return true;
98-
]]>
99-
</Code>
100-
</Task>
101-
</UsingTask>
102-
103-
<UsingTask TaskName="CheckIfVBCSCompilerWillOverride" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
104-
<ParameterGroup>
105-
<Src ParameterType="System.String" Required="true" />
106-
<Dest ParameterType="System.String" Required="true" />
107-
<WillOverride ParameterType="System.Boolean" Output="true" />
108-
</ParameterGroup>
109-
<Task>
110-
<Reference Include="System.IO" />
111-
<Code Type="Fragment" Language="cs">
112-
<![CDATA[
113-
WillOverride = false;
114-
try {
115-
WillOverride = File.Exists(Src) && File.Exists(Dest) && (File.GetLastWriteTime(Src) != File.GetLastWriteTime(Dest));
116-
}
117-
catch { }
118-
]]>
119-
</Code>
120-
</Task>
121-
</UsingTask>
12254
</Project>

0 commit comments

Comments
 (0)