Skip to content

Commit f62a6f5

Browse files
authored
Merge pull request #13 from dotnet-campus/t/lindexi
2 parents e580206 + 524dc9c commit f62a6f5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+575
-3314
lines changed

.github/workflows/NuGet-tag-publish.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ jobs:
1212

1313
steps:
1414
- uses: actions/checkout@v1
15-
16-
- name: Setup .NET Core
17-
uses: actions/setup-dotnet@v1
18-
with:
19-
dotnet-version: 3.1.300
2015

2116
- name: Install dotnet tool
2217
run: dotnet tool install -g dotnetCampus.TagToVersion

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,4 @@ $RECYCLE.BIN/
234234
# VS 编译中间文件
235235
*_wpftmp.csproj
236236
**/SourceProject/*.Source.SourceProject.props
237+
launchSettings.json
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
<Target Name="CopyOutputLibToFastDebug" AfterTargets="AfterBuild"
19+
Condition="$(EnableUsingMSBuildCopyOutputFileToFastDebug)==true">
20+
21+
<ItemGroup>
22+
<OutputFileToCopy Include="$(OutputPath)$(AssemblyName).dll"></OutputFileToCopy>
23+
<!-- 没有pdb文件拷贝过去,将会在调试提示没有符号,因此需要加上符号 -->
24+
<OutputFileToCopy Include="$(OutputPath)$(AssemblyName).pdb"></OutputFileToCopy>
25+
</ItemGroup>
26+
27+
<PropertyGroup>
28+
<OutputFileToCopyList>"@(OutputFileToCopy)"</OutputFileToCopyList>
29+
<MainProjectExecutablePathCommandArgs Condition="'$(MainProjectExecutablePath)' != ''">-MainProjectExecutablePath $(MainProjectExecutablePath)</MainProjectExecutablePathCommandArgs>
30+
</PropertyGroup>
31+
32+
<Exec
33+
Command="dotnet $(UsingMSBuildCopyOutputFileToFastDebugTaskFile) -- CopyOutputFile $(MainProjectExecutablePathCommandArgs) -CleanFilePath $(CleanUsingMSBuildCopyOutputFileToFastDebugFile) -OutputFileToCopyList $(OutputFileToCopyList) -TargetFramework $(TargetFramework)" />
34+
</Target>
35+
36+
<Target Name="BanCopyOutputLibToFastDebug" AfterTargets="AfterBuild"
37+
Condition="$(EnableUsingMSBuildCopyOutputFileToFastDebug)!=true">
38+
<Message Text="禁用 UsingMSBuildCopyOutputFileToFastDebug 因为 EnableUsingMSBuildCopyOutputFileToFastDebug 不为 true 值" />
39+
</Target>
40+
41+
<Target Name="UsingMSBuildCopyOutputFileToFastDebugClean" AfterTargets="Clean">
42+
<Exec
43+
Command="dotnet $(UsingMSBuildCopyOutputFileToFastDebugTaskFile) -- Clean -CleanFilePath $(CleanUsingMSBuildCopyOutputFileToFastDebugFile) " />
44+
</Target>
45+
</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.
Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,72 @@
11
using System;
2-
using System.Diagnostics;
3-
using System.Dynamic;
4-
using System.Globalization;
2+
using System.Collections.Generic;
53
using System.IO;
6-
using System.Runtime.Serialization.Json;
7-
using System.Xml;
8-
using Lsj.Util.Collections;
9-
using Lsj.Util.JSON;
10-
using Microsoft.Build.Framework;
11-
//using Newtonsoft.Json;
12-
//using Newtonsoft.Json.Linq;
4+
using System.Runtime.Serialization;
5+
using Newtonsoft.Json;
136

147
namespace UsingMSBuildCopyOutputFileToFastDebug
158
{
16-
public class LaunchSettingsParser : Microsoft.Build.Utilities.Task
9+
public class LaunchSettingsParser
1710
{
18-
/// <inheritdoc />
19-
public override bool Execute()
11+
public bool Execute()
2012
{
2113
var file = Path.Combine("Properties", "launchSettings.json");
22-
Console.WriteLine("开始从 launchSettings 文件读取输出文件夹");
23-
Console.WriteLine($"开始读取{file}文件");
14+
Console.WriteLine($"开始从 launchSettings({file}) 文件读取输出文件夹");
2415
if (!File.Exists(file))
2516
{
2617
Console.WriteLine($"找不到{file}文件,读取结束");
27-
return true;
18+
return false;
2819
}
2920

3021
var text = File.ReadAllText(file);
3122

32-
var o = JSONParser.Parse(text);
33-
var profiles = o.profiles;
34-
var data = profiles.data;
35-
if (data is SafeDictionary<string, object> d)
23+
var launchSettings = JsonConvert.DeserializeObject<LaunchSettings>(text);
24+
if (launchSettings == null)
3625
{
37-
foreach (var keyValuePair in d)
26+
return false;
27+
}
28+
29+
foreach (var launchSettingsProfile in launchSettings.Profiles)
30+
{
31+
var launchProfile = launchSettingsProfile.Value;
32+
if (launchProfile.CommandName == "Executable")
3833
{
39-
if (keyValuePair.Value is JSONObject jsonObject)
34+
var executablePath = launchProfile.ExecutablePath;
35+
if (executablePath != null)
4036
{
41-
if (jsonObject.TryGetMember(new CustomGetMemberBinder("ExecutablePath", true),
42-
out var filePath))
43-
{
44-
var path = filePath?.ToString();
45-
46-
if (!string.IsNullOrEmpty(path))
47-
{
48-
LaunchMainProjectPath = Path.GetDirectoryName(path);
49-
Console.WriteLine($"读取到 {LaunchMainProjectPath} 文件夹");
50-
return true;
51-
}
52-
}
37+
// executablePath = C:\lindexi\foo\foo.exe
38+
LaunchMainProjectExecutablePath = executablePath.ToString();
39+
return true;
5340
}
5441
}
5542
}
5643

57-
return true;
44+
return false;
5845
}
5946

60-
[Output]
61-
public string LaunchMainProjectPath { set; get; }
47+
public string LaunchMainProjectExecutablePath { set; get; }
6248
}
6349

64-
public class CustomGetMemberBinder : GetMemberBinder
50+
[DataContract]
51+
public class LaunchSettings
6552
{
66-
/// <inheritdoc />
67-
public CustomGetMemberBinder(string name, bool ignoreCase) : base(name, ignoreCase)
68-
{
69-
}
53+
[DataMember(Name = "profiles")]
54+
public IDictionary<string, LaunchProfile> Profiles { get; set; }
55+
}
7056

71-
/// <inheritdoc />
72-
public override DynamicMetaObject FallbackGetMember(DynamicMetaObject target, DynamicMetaObject errorSuggestion)
73-
{
74-
return null;
75-
}
57+
[DataContract]
58+
public class LaunchProfile
59+
{
60+
[DataMember(Name = "commandName")]
61+
public string CommandName { get; set; }
62+
63+
[DataMember(Name = "executablePath")]
64+
public string ExecutablePath { get; set; }
65+
66+
[DataMember(Name = "commandLineArgs")]
67+
public string CommandLineArgs { get; set; }
68+
69+
[DataMember(Name = "nativeDebugging")]
70+
public bool NativeDebugging { get; set; }
7671
}
7772
}

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)