Skip to content

Commit dfb6a22

Browse files
committed
干掉使用 MSTask 的方法,换成使用命令行的方式,用于支持 .NET 高版本
在新版本的 MSBuild 支持 x64 版本,此时加载 Task 偶尔将会失败
1 parent e580206 commit dfb6a22

45 files changed

Lines changed: 222 additions & 3261 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<Project>
2+
<PropertyGroup>
3+
<NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder >$(MSBuildThisFileDirectory)..\tools\</NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder>
4+
<UsingMSBuildCopyOutputFileToFastDebugTaskFile>"$(NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder)UsingMSBuildCopyOutputFileToFastDebug.dll"</UsingMSBuildCopyOutputFileToFastDebugTaskFile>
5+
</PropertyGroup>
6+
7+
<!--默认只有在 Debug 下开启-->
8+
<PropertyGroup Condition="$(EnableUsingMSBuildCopyOutputFileToFastDebug)==''">
9+
<EnableUsingMSBuildCopyOutputFileToFastDebug Condition="'$(Configuration)' == 'Debug'">true</EnableUsingMSBuildCopyOutputFileToFastDebug>
10+
<EnableUsingMSBuildCopyOutputFileToFastDebug Condition="'$(Configuration)' != 'Debug'">false</EnableUsingMSBuildCopyOutputFileToFastDebug>
11+
</PropertyGroup>
12+
13+
<!-- 清理文件 -->
14+
<PropertyGroup>
15+
<CleanUsingMSBuildCopyOutputFileToFastDebugFile>"$(IntermediateOutputPath)CleanUsingMSBuildCopyOutputFileToFastDebugFile.txt"</CleanUsingMSBuildCopyOutputFileToFastDebugFile>
16+
</PropertyGroup>
17+
18+
<!-- <UsingTask TaskName="UsingMSBuildCopyOutputFileToFastDebug.SafeOutputFileCopyTask" -->
19+
<!-- AssemblyFile="$(NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder)\UsingMSBuildCopyOutputFileToFastDebug.dll" /> -->
20+
<!-- <UsingTask TaskName="UsingMSBuildCopyOutputFileToFastDebug.LaunchSettingsParser" -->
21+
<!-- AssemblyFile="$(NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder)\UsingMSBuildCopyOutputFileToFastDebug.dll" /> -->
22+
23+
24+
25+
<Target Name="CopyOutputLibToFastDebug" AfterTargets="AfterBuild" Condition="$(EnableUsingMSBuildCopyOutputFileToFastDebug)==true">
26+
27+
<ItemGroup>
28+
<OutputFileToCopy Include="$(OutputPath)$(AssemblyName).dll"></OutputFileToCopy>
29+
<!-- 没有pdb文件拷贝过去,将会在调试提示没有符号,因此需要加上符号 -->
30+
<OutputFileToCopy Include="$(OutputPath)$(AssemblyName).pdb"></OutputFileToCopy>
31+
</ItemGroup>
32+
33+
<PropertyGroup>
34+
<OutputFileToCopyList>"@(OutputFileToCopy)"</OutputFileToCopyList>
35+
</PropertyGroup>
36+
37+
<Exec Command="dotnet $(UsingMSBuildCopyOutputFileToFastDebugTaskFile) -- CopyOutputFile -MainProjectPath $(MainProjectPath) -CleanFilePath $(CleanUsingMSBuildCopyOutputFileToFastDebugFile) -OutputFileToCopyList $(OutputFileToCopyList)"/>
38+
</Target>
39+
40+
<!--<Target Name="ParseLaunchSettings" AfterTargets="AfterBuild"
41+
BeforeTargets="CopyOutputLibToFastDebug" Condition="$(MainProjectPath)=='' and $(EnableUsingMSBuildCopyOutputFileToFastDebug)==true">
42+
<Message Text="当前使用的复制方法 $(NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder)" />
43+
<LaunchSettingsParser>
44+
<Output TaskParameter="LaunchMainProjectPath" PropertyName="LaunchMainProjectPath" ></Output>
45+
</LaunchSettingsParser>
46+
</Target>-->
47+
48+
<Target Name="BanCopyOutputLibToFastDebug" AfterTargets="AfterBuild"
49+
Condition="$(EnableUsingMSBuildCopyOutputFileToFastDebug)!=true">
50+
<Message Text="禁用 UsingMSBuildCopyOutputFileToFastDebug 因为 EnableUsingMSBuildCopyOutputFileToFastDebug 不为 true 值"/>
51+
</Target>
52+
53+
<!--<Target Name="CopyOutputLibToFastDebug" AfterTargets="AfterBuild"
54+
Condition="($(MainProjectPath)!='' or $(LaunchMainProjectPath)!='') and $(EnableUsingMSBuildCopyOutputFileToFastDebug)==true">
55+
<Message Text="当前使用的复制方法 $(NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder)" />
56+
<ItemGroup>
57+
<OutputFileToCopy Include="$(OutputPath)$(AssemblyName).dll"></OutputFileToCopy>
58+
<OutputFileToCopy Include="$(OutputPath)$(AssemblyName).pdb"></OutputFileToCopy>
59+
</ItemGroup>
60+
<SafeOutputFileCopyTask SourceFiles="@(OutputFileToCopy)"
61+
DestinationFolder="$(MainProjectPath)"
62+
CleanFile="$(CleanUsingMSBuildCopyOutputFileToFastDebugFile)"
63+
Condition="$(MainProjectPath)!=''"></SafeOutputFileCopyTask>
64+
65+
<SafeOutputFileCopyTask SourceFiles="@(OutputFileToCopy)"
66+
DestinationFolder="$(LaunchMainProjectPath)"
67+
CleanFile="$(CleanUsingMSBuildCopyOutputFileToFastDebugFile)"
68+
Condition="$(LaunchMainProjectPath)!='' and $(MainProjectPath)==''"></SafeOutputFileCopyTask>
69+
</Target>-->
70+
71+
<Target Name="UsingMSBuildCopyOutputFileToFastDebugClean" AfterTargets="Clean">
72+
<Exec Command="dotnet $(UsingMSBuildCopyOutputFileToFastDebugTaskFile) -- Clean -CleanFilePath $(CleanUsingMSBuildCopyOutputFileToFastDebugFile) "/>
73+
<!--<ReadLinesFromFile
74+
File="$(CleanUsingMSBuildCopyOutputFileToFastDebugFile)" >
75+
<Output
76+
TaskParameter="Lines"
77+
ItemName="UsingMSBuildCopyOutputFileToFastDebugCleanFile"/>
78+
</ReadLinesFromFile>
79+
80+
<Delete Files="@(UsingMSBuildCopyOutputFileToFastDebugCleanFile)" >
81+
<Output TaskParameter="DeletedFiles" ItemName="UsingMSBuildCopyOutputFileToFastDebugCleanFileDeletedList"/>
82+
</Delete>
83+
84+
<Message Text="Deleted files: '@(UsingMSBuildCopyOutputFileToFastDebugCleanFileDeletedList)'"/>-->
85+
</Target>
86+
</Project>

Code/UsingMSBuildCopyOutputFileToFastDebug/BuildMultiTargeting/dotnetCampus.UsingMSBuildCopyOutputFileToFastDebug.targets renamed to Code/ToolPackager/BuildMultiTargeting/dotnetCampus.UsingMSBuildCopyOutputFileToFastDebug.targets

File renamed without changes.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<!--让多个不同的框架都能使用此工具-->
5+
<TargetFrameworks>net5.0;net45;netstandard1.0</TargetFrameworks>
6+
</PropertyGroup>
7+
8+
<PropertyGroup>
9+
<!-- 程序集名不是将打包的 -->
10+
<PackageId>dotnetCampus.UsingMSBuildCopyOutputFileToFastDebug</PackageId>
11+
12+
<!-- 没有包含输出到 NuGet 的 Lib 文件夹的内容,不要警告 -->
13+
<NoPackageAnalysis>true</NoPackageAnalysis>
14+
<!-- 不包含任何构建的输出文件,这只是一个打包项目而已 -->
15+
<IncludeBuildOutput>false</IncludeBuildOutput>
16+
17+
<!-- 这是一个开发辅助的库 -->
18+
<DevelopmentDependency>true</DevelopmentDependency>
19+
20+
</PropertyGroup>
21+
22+
<ItemGroup>
23+
<!-- 仅仅只是设置设置项目构建顺序而已 -->
24+
<ProjectReference Include="..\UsingMSBuildCopyOutputFileToFastDebug\UsingMSBuildCopyOutputFileToFastDebug.csproj" Condition="'$(TargetFramework)' == 'net5.0'" ReferenceOutputAssembly="false" />
25+
</ItemGroup>
26+
27+
<PropertyGroup>
28+
<!-- 将实际执行的项目的输出作为工具 -->
29+
<UsingMSBuildCopyOutputFileToFastDebugOutputPath Condition="'$(Configuration)'=='Debug'">..\UsingMSBuildCopyOutputFileToFastDebug\bin\Debug\net5.0\</UsingMSBuildCopyOutputFileToFastDebugOutputPath>
30+
31+
<UsingMSBuildCopyOutputFileToFastDebugOutputPath Condition="'$(Configuration)'!='Debug'">..\UsingMSBuildCopyOutputFileToFastDebug\bin\Release\net5.0\</UsingMSBuildCopyOutputFileToFastDebugOutputPath>
32+
</PropertyGroup>
33+
34+
<Target Name="UsingMSBuildCopyOutputFileToFastDebugPackage" BeforeTargets="_GetPackageFiles">
35+
<ItemGroup>
36+
<None Include="build\dotnetCampus.UsingMSBuildCopyOutputFileToFastDebug.targets" Pack="True" PackagePath="\build\$(PackageId).targets" />
37+
<None Include="buildMultiTargeting\dotnetCampus.UsingMSBuildCopyOutputFileToFastDebug.targets" Pack="True" PackagePath="\buildMultiTargeting" />
38+
<None Include="$(UsingMSBuildCopyOutputFileToFastDebugOutputPath)**" Pack="true" PackagePath="\tools"/>
39+
</ItemGroup>
40+
</Target>
41+
42+
</Project>

Code/UsingMSBuildCopyOutputFileToFastDebug/Build/dotnetCampus.UsingMSBuildCopyOutputFileToFastDebug.targets

Lines changed: 0 additions & 70 deletions
This file was deleted.

Code/UsingMSBuildCopyOutputFileToFastDebug/LaunchSettingsParser.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@
44
using System.Globalization;
55
using System.IO;
66
using System.Runtime.Serialization.Json;
7+
using System.Text.Json;
8+
using System.Text.Json.Serialization;
79
using System.Xml;
810
using Lsj.Util.Collections;
911
using Lsj.Util.JSON;
10-
using Microsoft.Build.Framework;
11-
//using Newtonsoft.Json;
12-
//using Newtonsoft.Json.Linq;
1312

1413
namespace UsingMSBuildCopyOutputFileToFastDebug
1514
{
16-
public class LaunchSettingsParser : Microsoft.Build.Utilities.Task
15+
public class LaunchSettingsParser
1716
{
18-
/// <inheritdoc />
19-
public override bool Execute()
17+
public bool Execute()
2018
{
2119
var file = Path.Combine("Properties", "launchSettings.json");
2220
Console.WriteLine("开始从 launchSettings 文件读取输出文件夹");
@@ -57,7 +55,6 @@ public override bool Execute()
5755
return true;
5856
}
5957

60-
[Output]
6158
public string LaunchMainProjectPath { set; get; }
6259
}
6360

Code/UsingMSBuildCopyOutputFileToFastDebug/Lsj.Util.JSON/CustomJsonPropertyNameAttribute.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.

Code/UsingMSBuildCopyOutputFileToFastDebug/Lsj.Util.JSON/CustomSerializeAttribute.cs

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)