Skip to content

Commit 85b71ce

Browse files
authored
Merge pull request #4 from dotnet-campus/t/lindexi
输出到主项目的文件
2 parents 93d5668 + 05bd067 commit 85b71ce

41 files changed

Lines changed: 3492 additions & 160 deletions

Some content is hidden

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

.github/workflows/PublishNuget.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: publish nuget
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
build:
10+
11+
runs-on: windows-latest
12+
13+
steps:
14+
- uses: actions/checkout@v1
15+
16+
- name: Setup .NET Core
17+
uses: actions/setup-dotnet@v1
18+
with:
19+
dotnet-version: 3.1.102
20+
- name: Build with dotnet
21+
run: |
22+
dotnet build --configuration Release
23+
- name: Install Nuget
24+
run: |
25+
$sourceNugetExe = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
26+
$targetNugetExe = "nuget.exe"
27+
Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe
28+
- name: Add private GitHub registry to NuGet
29+
run: |
30+
.\nuget sources add -name github -Source https://nuget.pkg.github.com/ORGANIZATION_NAME/index.json -Username ORGANIZATION_NAME -Password ${{ secrets.GITHUB_TOKEN }}
31+
- name: Push generated package to GitHub registry
32+
run: |
33+
.\nuget push .\bin\release\*.nupkg -Source github -SkipDuplicate
34+
.\nuget push .\bin\release\*.nupkg -Source https://api.nuget.org/v3/index.json -SkipDuplicate -ApiKey ${{ secrets.NugetKey }} -NoSymbols

.github/workflows/dotnetcore.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: .NET Core
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: windows-latest
9+
10+
steps:
11+
- uses: actions/checkout@v1
12+
- name: Build with dotnet
13+
run: dotnet build --configuration Release
Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,36 @@
1-
<Project>
2-
<PropertyGroup>
3-
<!-- 我们使用 $(MSBuildRuntimeType) 来判断编译器是 .NET Core 的还是 .NET Framework 的。
4-
然后选用对应的文件夹。-->
5-
<NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder Condition=" '$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)..\tools\netcoreapp2.2\</NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder>
6-
<NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder Condition=" '$(MSBuildRuntimeType)' != 'Core'">$(MSBuildThisFileDirectory)..\tools\net48\</NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder>
7-
</PropertyGroup>
8-
<UsingTask TaskName="UsingMSBuildCopyOutputFileToFastDebug.SafeOutputFileCopyTask"
9-
AssemblyFile="$(NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder)\UsingMSBuildCopyOutputFileToFastDebug.dll" />
10-
11-
<Target Name="CopyOutputLibToFastDebug" AfterTargets="AfterBuild"
12-
Condition="$(MainProjectPath)!=''">
13-
<Message Text="当前使用的复制方法 $(NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder)" />
14-
<ItemGroup>
15-
<OutputFileToCopy Include="$(OutputPath)$(AssemblyName).dll"></OutputFileToCopy>
16-
<OutputFileToCopy Include="$(OutputPath)$(AssemblyName).pdb"></OutputFileToCopy>
17-
</ItemGroup>
18-
<SafeOutputFileCopyTask SourceFiles="@(OutputFileToCopy)" DestinationFolder="$(MainProjectPath)"></SafeOutputFileCopyTask>
19-
</Target>
1+
<Project>
2+
<PropertyGroup>
3+
<!-- 我们使用 $(MSBuildRuntimeType) 来判断编译器是 .NET Core 的还是 .NET Framework 的。
4+
然后选用对应的文件夹。-->
5+
<NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder Condition=" '$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)..\tools\netcoreapp2.2\</NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder>
6+
<NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder Condition=" '$(MSBuildRuntimeType)' != 'Core'">$(MSBuildThisFileDirectory)..\tools\net48\</NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder>
7+
</PropertyGroup>
8+
9+
<UsingTask TaskName="UsingMSBuildCopyOutputFileToFastDebug.SafeOutputFileCopyTask"
10+
AssemblyFile="$(NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder)\UsingMSBuildCopyOutputFileToFastDebug.dll" />
11+
<UsingTask TaskName="UsingMSBuildCopyOutputFileToFastDebug.LaunchSettingsParser"
12+
AssemblyFile="$(NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder)\UsingMSBuildCopyOutputFileToFastDebug.dll" />
13+
14+
<Target Name="ParseLaunchSettings" AfterTargets="AfterBuild"
15+
BeforeTargets="CopyOutputLibToFastDebug" Condition="$(MainProjectPath)==''">
16+
<Message Text="当前使用的复制方法 $(NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder)" />
17+
<LaunchSettingsParser>
18+
<Output TaskParameter="LaunchMainProjectPath" PropertyName="LaunchMainProjectPath" ></Output>
19+
</LaunchSettingsParser>
20+
</Target>
21+
22+
23+
<Target Name="CopyOutputLibToFastDebug" AfterTargets="AfterBuild"
24+
Condition="$(MainProjectPath)!='' or $(LaunchMainProjectPath)!=''">
25+
<Message Text="当前使用的复制方法 $(NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder)" />
26+
<ItemGroup>
27+
<OutputFileToCopy Include="$(OutputPath)$(AssemblyName).dll"></OutputFileToCopy>
28+
<OutputFileToCopy Include="$(OutputPath)$(AssemblyName).pdb"></OutputFileToCopy>
29+
</ItemGroup>
30+
<SafeOutputFileCopyTask SourceFiles="@(OutputFileToCopy)" DestinationFolder="$(MainProjectPath)"
31+
Condition="$(MainProjectPath)!=''"></SafeOutputFileCopyTask>
32+
33+
<SafeOutputFileCopyTask SourceFiles="@(OutputFileToCopy)" DestinationFolder="$(LaunchMainProjectPath)"
34+
Condition="$(LaunchMainProjectPath)!='' and $(MainProjectPath)==''"></SafeOutputFileCopyTask>
35+
</Target>
2036
</Project>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.Dynamic;
4+
using System.Globalization;
5+
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;
13+
14+
namespace UsingMSBuildCopyOutputFileToFastDebug
15+
{
16+
public class LaunchSettingsParser : Microsoft.Build.Utilities.Task
17+
{
18+
/// <inheritdoc />
19+
public override bool Execute()
20+
{
21+
var file = Path.Combine("Properties", "launchSettings.json");
22+
Console.WriteLine("开始从 launchSettings 文件读取输出文件夹");
23+
Console.WriteLine($"开始读取{file}文件");
24+
if (!File.Exists(file))
25+
{
26+
Console.WriteLine($"找不到{file}文件,读取结束");
27+
}
28+
29+
var text = File.ReadAllText(file);
30+
31+
var o = JSONParser.Parse(text);
32+
var profiles = o.profiles;
33+
var data = profiles.data;
34+
if (data is SafeDictionary<string, object> d)
35+
{
36+
foreach (var keyValuePair in d)
37+
{
38+
if (keyValuePair.Value is JSONObject jsonObject)
39+
{
40+
if (jsonObject.TryGetMember(new CustomGetMemberBinder("ExecutablePath", true),
41+
out var filePath))
42+
{
43+
var path = filePath?.ToString();
44+
45+
if (!string.IsNullOrEmpty(path))
46+
{
47+
LaunchMainProjectPath = Path.GetDirectoryName(path);
48+
Console.WriteLine($"读取到 {LaunchMainProjectPath} 文件夹");
49+
return true;
50+
}
51+
}
52+
}
53+
}
54+
}
55+
56+
return true;
57+
}
58+
59+
[Output]
60+
public string LaunchMainProjectPath { set; get; }
61+
}
62+
63+
public class CustomGetMemberBinder : GetMemberBinder
64+
{
65+
/// <inheritdoc />
66+
public CustomGetMemberBinder(string name, bool ignoreCase) : base(name, ignoreCase)
67+
{
68+
}
69+
70+
/// <inheritdoc />
71+
public override DynamicMetaObject FallbackGetMember(DynamicMetaObject target, DynamicMetaObject errorSuggestion)
72+
{
73+
return null;
74+
}
75+
}
76+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
3+
namespace Lsj.Util.JSON
4+
{
5+
/// <summary>
6+
/// Custom Json Property Name Attribute
7+
/// </summary>
8+
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
9+
public class CustomJsonPropertyNameAttribute : Attribute
10+
{
11+
/// <summary>
12+
/// Json Property Name
13+
/// </summary>
14+
public string Name { get; set; }
15+
16+
/// <summary>
17+
///
18+
/// </summary>
19+
/// <param name="name"></param>
20+
public CustomJsonPropertyNameAttribute(string name)
21+
{
22+
this.Name = name;
23+
}
24+
}
25+
}
26+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
3+
namespace Lsj.Util.JSON
4+
{
5+
/// <summary>
6+
/// Custom Seriailize Attribute
7+
/// </summary>
8+
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
9+
public class CustomSerializeAttribute : Attribute
10+
{
11+
/// <summary>
12+
/// Serializer Type
13+
/// </summary>
14+
public Type Serializer { get; set; }
15+
/// <summary>
16+
/// Json Source Type
17+
/// </summary>
18+
public Type SourceType { get; set; }
19+
20+
/// <summary>
21+
///
22+
/// </summary>
23+
public CustomSerializeAttribute()
24+
{
25+
}
26+
}
27+
28+
/// <summary>
29+
/// ISerializer
30+
/// </summary>
31+
public interface ISerializer
32+
{
33+
/// <summary>
34+
/// Convert
35+
/// </summary>
36+
/// <param name="obj">object</param>
37+
/// <returns></returns>
38+
object Convert(object obj);
39+
40+
/// <summary>
41+
/// Parse
42+
/// </summary>
43+
/// <param name="str">json str</param>
44+
/// <returns></returns>
45+
object Parse(object str);
46+
}
47+
}
48+
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Runtime.CompilerServices;
4+
using Microsoft.CSharp.RuntimeBinder;
5+
using Lsj.Util.Text;
6+
7+
namespace Lsj.Util.Dynamic
8+
{
9+
/// <summary>
10+
/// Dynamic Helper
11+
/// </summary>
12+
public static class DynamicHelper
13+
{
14+
/// <summary>
15+
/// Get Member
16+
/// </summary>
17+
/// <param name="obj"></param>
18+
/// <param name="memberName">member name</param>
19+
/// <returns>value</returns>
20+
public static object GetMember(this object obj, string memberName)
21+
{
22+
var binder = Binder.GetMember(CSharpBinderFlags.None, memberName, obj.GetType(), new List<CSharpArgumentInfo> { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) });
23+
var callsite = CallSite<Func<CallSite, object, object>>.Create(binder);
24+
return callsite.Target(callsite, obj);
25+
}
26+
27+
/// <summary>
28+
/// Set Member
29+
/// </summary>
30+
/// <param name="obj"></param>
31+
/// <param name="memberName">member name</param>
32+
/// <param name="value">value</param>
33+
public static void SetMember(this object obj, string memberName, object value)
34+
{
35+
var binder = Binder.SetMember(CSharpBinderFlags.None, memberName, obj.GetType(), new List<CSharpArgumentInfo> { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) });
36+
var callsite = CallSite<Func<CallSite, object, object, object>>.Create(binder);
37+
callsite.Target(callsite, obj, value);
38+
}
39+
40+
/// <summary>
41+
/// Cast
42+
/// </summary>
43+
/// <typeparam name="T"></typeparam>
44+
/// <param name="obj"></param>
45+
/// <returns></returns>
46+
public static T Cast<T>(this object obj)
47+
{
48+
return (T)obj;
49+
}
50+
51+
/// <summary>
52+
/// Cast and Assign
53+
/// </summary>
54+
/// <param name="toAssign"></param>
55+
/// <param name="val"></param>
56+
/// <returns></returns>
57+
public static bool AutoCastAndAssign(ref string toAssign, object val)
58+
{
59+
toAssign = val.ToString();
60+
return true;
61+
}
62+
63+
/// <summary>
64+
/// Cast and Assign
65+
/// </summary>
66+
/// <param name="toAssign"></param>
67+
/// <param name="val"></param>
68+
/// <returns></returns>
69+
public static bool AutoCastAndAssign(ref int toAssign, object val)
70+
{
71+
if (val.IsNumeric())
72+
{
73+
toAssign = (int)val;
74+
return true;
75+
}
76+
else
77+
{
78+
var str = (val as object).ToString();
79+
var intVal = str.ConvertToIntWithNull();
80+
if (intVal != null)
81+
{
82+
toAssign = intVal.Value;
83+
return true;
84+
}
85+
else
86+
{
87+
return false;
88+
}
89+
}
90+
}
91+
92+
/// <summary>
93+
/// Cast and Assign
94+
/// </summary>
95+
/// <param name="toAssign"></param>
96+
/// <param name="val"></param>
97+
/// <returns></returns>
98+
public static bool AutoCastAndAssign(ref decimal toAssign, object val)
99+
{
100+
if (val.IsNumeric())
101+
{
102+
toAssign = (int)val;
103+
return true;
104+
}
105+
else
106+
{
107+
var str = (val as object).ToString();
108+
var decimalVal = str.ConvertToDecimalWithNull();
109+
if (decimalVal != null)
110+
{
111+
toAssign = decimalVal.Value;
112+
return true;
113+
}
114+
else
115+
{
116+
return false;
117+
}
118+
}
119+
}
120+
}
121+
}

0 commit comments

Comments
 (0)