You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

67 lines
3.3 KiB

  1. <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  2. <ItemGroup>
  3. <RoslyCompilerFiles Include="$(CscToolPath)\*">
  4. <Link>roslyn\%(RecursiveDir)%(Filename)%(Extension)</Link>
  5. </RoslyCompilerFiles>
  6. </ItemGroup>
  7. <Target Name="IncludeRoslynCompilerFilesToFilesForPackagingFromProject" BeforeTargets="PrepareForRun" >
  8. <ItemGroup>
  9. <FilesForPackagingFromProject Include="@(RoslyCompilerFiles)">
  10. <DestinationRelativePath>bin\roslyn\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
  11. <FromTarget>IncludeRoslynCompilerFilesToFilesForPackagingFromProject</FromTarget>
  12. <Category>Run</Category>
  13. </FilesForPackagingFromProject>
  14. </ItemGroup>
  15. </Target>
  16. <Target Name="CopyRoslynCompilerFilesToOutputDirectory" AfterTargets="CopyFilesToOutputDirectory">
  17. <Copy SourceFiles="@(RoslyCompilerFiles)" DestinationFolder="$(WebProjectOutputDir)\bin\roslyn" ContinueOnError="true" SkipUnchangedFiles="true" Retries="0" />
  18. </Target>
  19. <Target Name = "KillVBCSCompilerAndRetryCopy" AfterTargets="CopyRoslynCompilerFilesToOutputDirectory" Condition="'$(MSBuildLastTaskResult)' == 'False'" >
  20. <KillProcess ProcessName="VBCSCompiler" ImagePath="$(WebProjectOutputDir)" />
  21. <Copy SourceFiles="@(RoslyCompilerFiles)" DestinationFolder="$(WebProjectOutputDir)\bin\roslyn" ContinueOnError="true" SkipUnchangedFiles="true" />
  22. </Target>
  23. <UsingTask TaskName="KillProcess" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
  24. <ParameterGroup>
  25. <ProcessName ParameterType="System.String" Required="true" />
  26. <ImagePath ParameterType="System.String" Required="true" />
  27. </ParameterGroup>
  28. <Task>
  29. <Reference Include="System" />
  30. <Reference Include="System.Management" />
  31. <Using Namespace="System" />
  32. <Using Namespace="System.Linq" />
  33. <Using Namespace="System.Diagnostics" />
  34. <Using Namespace="System.Management" />
  35. <Code Type="Fragment" Language="cs">
  36. <![CDATA[
  37. try
  38. {
  39. foreach(var p in Process.GetProcessesByName(ProcessName))
  40. {
  41. var wmiQuery = "SELECT ProcessId, ExecutablePath FROM Win32_Process WHERE ProcessId = " + p.Id;
  42. using(var searcher = new ManagementObjectSearcher(wmiQuery))
  43. {
  44. using(var results = searcher.Get())
  45. {
  46. var mo = results.Cast<ManagementObject>().FirstOrDefault();
  47. Log.LogMessage("ExecutablePath is {0}", (string)mo["ExecutablePath"]);
  48. if(mo != null && string.Compare((string)mo["ExecutablePath"], ImagePath, StringComparison.OrdinalIgnoreCase) > 0)
  49. {
  50. p.Kill();
  51. Log.LogMessage("{0} is killed", (string)mo["ExecutablePath"]);
  52. break;
  53. }
  54. }
  55. }
  56. }
  57. }
  58. catch (Exception ex)
  59. {
  60. Log.LogErrorFromException(ex);
  61. }
  62. return true;
  63. ]]>
  64. </Code>
  65. </Task>
  66. </UsingTask>
  67. </Project>