Skip to content

Commit

Permalink
Exclude appsettings.config from publish file package.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmoonlight committed Nov 18, 2019
1 parent d8706b0 commit e23cb33
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 25 deletions.
17 changes: 15 additions & 2 deletions src/NSmartProxy.Infrastructure/ConfigHelper.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
using Newtonsoft.Json;
using System.Diagnostics;
using System.Dynamic;
using Newtonsoft.Json;
using NSmartProxy.Data;
using System.IO;

namespace NSmartProxy.Infrastructure
{
public static class ConfigHelper
{
public static string AppSettingFullPath
{
get
{
var processModule = Process.GetCurrentProcess().MainModule;
return Path.GetDirectoryName(processModule?.FileName)
+ Path.DirectorySeparatorChar
+ "appsettings.json";
}
}

/// <summary>
/// 读配置
/// </summary>
Expand Down Expand Up @@ -38,7 +51,7 @@ public static T SaveChanges<T>(this T config, string path)
IndentChar = ' '
};
serializer.Serialize(jsonWriter, config);

sw.Close();
}

Expand Down
4 changes: 3 additions & 1 deletion src/NSmartProxy.Infrastructure/StringUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using NSmartProxy.Data;
using NSmartProxy.Infrastructure;
Expand Down Expand Up @@ -216,7 +217,7 @@ public static bool IsNum(this string str)
/// <param name="offset"></param>
/// <param name="length"></param>
/// <returns></returns>
public static byte[] DecompressInSnappy(byte[] compressed,int offset ,int length)
public static byte[] DecompressInSnappy(byte[] compressed, int offset, int length)
{
SnappyDecompressor sd = new SnappyDecompressor();
try
Expand All @@ -225,6 +226,7 @@ public static byte[] DecompressInSnappy(byte[] compressed,int offset ,int length
}
catch (Exception ex)
{
_ = ex;
//啥情況?
return null;
}
Expand Down
6 changes: 4 additions & 2 deletions src/NSmartProxy.ServerHost/NSmartProxy.ServerHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
</ItemGroup>

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<None Include="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToPublishDirectory>Always</CopyToPublishDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</None>
<None Update="log4net.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down
18 changes: 9 additions & 9 deletions src/NSmartProxy.ServerHost/ServerHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace NSmartProxy.ServerHost
{
public class ServerHost:IMicroService
public class ServerHost : IMicroService
{

private static Mutex mutex = new Mutex(true, "{8639B0AD-A27C-4F15-B3D9-08035D0FC6D6}");
Expand Down Expand Up @@ -45,7 +45,7 @@ public void Info(object message)

public IConfigurationRoot Configuration { get; set; }

public const string CONFIG_FILE_PATH = "./appsettings.json";
private static readonly string ConfigFilePath = ConfigHelper.AppSettingFullPath;

public void Start()
{
Expand Down Expand Up @@ -74,7 +74,7 @@ private void InitLogConfig()
Logger.Debug($"*** {NSPVersion.NSmartProxyServerName} ***");
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile(CONFIG_FILE_PATH);
.AddJsonFile(ConfigFilePath);

Configuration = builder.Build();
}
Expand All @@ -83,17 +83,17 @@ private static void StartNSPServer()
{
NSPServerConfig serverConfig = null;
//初始化配置
if (!File.Exists(CONFIG_FILE_PATH))
if (!File.Exists(ConfigFilePath))
{
serverConfig = new NSPServerConfig();
serverConfig.SaveChanges(CONFIG_FILE_PATH);
serverConfig.SaveChanges(ConfigFilePath);
}
else
{
serverConfig = ConfigHelper.ReadAllConfig<NSPServerConfig>(CONFIG_FILE_PATH);
serverConfig = ConfigHelper.ReadAllConfig<NSPServerConfig>(ConfigFilePath);
}



Server srv = new Server(new Log4netLogger());

Expand All @@ -108,7 +108,7 @@ private static void StartNSPServer()
srv
.SetConfiguration(serverConfig)
.SetAnonymousLogin(true)
.SetServerConfigPath(CONFIG_FILE_PATH)
.SetServerConfigPath(ConfigFilePath)
.Start()
.Wait();
}
Expand Down Expand Up @@ -150,7 +150,7 @@ private static void StartNSPServer()
public void Stop()
{
//
Console.WriteLine(NSPVersion.NSmartProxyClientName +" STOPPED.");
Console.WriteLine(NSPVersion.NSmartProxyClientName + " STOPPED.");
Environment.Exit(0);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/NSmartProxyClient/NSmartProxyClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ public void Info(object message)
public static ILog Logger;
public static IConfigurationRoot Configuration { get; set; }
private static LoginInfo _currentLoginInfo;
private static string appSettingFilePath;
private static readonly string ConfigFilePath = ConfigHelper.AppSettingFullPath;
public void Start(string[] args)
{
appSettingFilePath = Directory.GetCurrentDirectory() + "/appsettings.json";
//appSettingFilePath = Directory.GetCurrentDirectory() + "/appsettings.json";
//log
var loggerRepository = LogManager.CreateRepository("NSmartClientRouterRepository");
XmlConfigurator.Configure(loggerRepository, new FileInfo("log4net.config"));
Expand Down Expand Up @@ -88,7 +88,7 @@ private static async Task StartClient()

Router clientRouter = new Router(new Log4netLogger());
//read config from config file.
clientRouter.SetConfiguration(ConfigHelper.ReadAllConfig<NSPClientConfig>(appSettingFilePath));
clientRouter.SetConfiguration(ConfigHelper.ReadAllConfig<NSPClientConfig>(ConfigFilePath));
if (_currentLoginInfo != null)
{
clientRouter.SetLoginInfo(_currentLoginInfo);
Expand Down
11 changes: 6 additions & 5 deletions src/NSmartProxyClient/NSmartProxyClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
</ItemGroup>

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="log4net.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<!-- publishsinglefile时,排除配置文件在外 -->
<None Include="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToPublishDirectory>Always</CopyToPublishDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</None>

</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions src/NSmartProxyClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ static void Main()
ServiceRunner<NSmartProxyClient>.Run(config =>
{
var name = Global.NSPServerServiceName;
config.SetDisplayName(Global.NSPServerServiceName);
config.SetName(Global.NSPServerDisplayName);
config.SetDescription(NSPVersion.NSmartProxyServerName);
config.SetDisplayName(Global.NSPClientServiceName);
config.SetName(Global.NSPClientServiceDisplayName);
config.SetDescription(NSPVersion.NSmartProxyClientName);

config.Service(serviceConfig =>
{
Expand Down
46 changes: 46 additions & 0 deletions src/build_test.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
rem windows only
rem NSP v1.2
@ECHO off

set Ver=v1.2pre3
set BuildPath=%~dp0../build

set nsp_client_path=%BuildPath%/nspclient_%Ver%
set nsp_server_path=%BuildPath%/nspserver_%Ver%


set nsp_client_scd_win_path=%BuildPath%/nspclient_scd_win_%Ver%



set nsp_server_scd_win_path=%BuildPath%/nspserver_scd_win_%Ver%


set nsp_client_winfform_path=%BuildPath%/nspclient_winform_%Ver%

rem del %~dp0/../build/*.*
rem NSPClient
dotnet publish .\NSmartProxyClient\NSmartProxyClient.csproj -c release -o %nsp_client_path%

rem NSPServer
dotnet publish .\NSmartProxy.ServerHost\NSmartProxy.ServerHost.csproj -c release -o %nsp_server_path%

rem NSPClient_SCD
dotnet publish .\NSmartProxyClient\NSmartProxyClient.csproj -r win-x64 -c Release /p:PublishSingleFile=true -o %nsp_client_scd_win_path%


rem NSPServer_SCD
dotnet publish .\NSmartProxy.ServerHost\NSmartProxy.ServerHost.csproj -r win-x64 -c Release /p:PublishSingleFile=true -o %nsp_server_scd_win_path%

rem NSPWinform
MSBuild .\NSmartProxyWinform\NSmartProxyWinform.csproj /t:build /p:OutDir=%nsp_client_winfform_path%
powershell del %nsp_client_winfform_path%/*.pdb
powershell del %nsp_client_winfform_path%/*.xml

rem ilmerge
rem ruined :<

rem compress

powershell explorer %~dp0..\build
pause

0 comments on commit e23cb33

Please sign in to comment.