mirror of
https://github.com/nsnail/NetAdmin.git
synced 2025-06-20 10:48:15 +08:00
build: 📦 nuget package与 project refrence 切换脚本 (#199)
Co-authored-by: tk <fiyne1a@dingtalk.com>
This commit is contained in:
42
scripts/switch.nuget.or.project.csx
Normal file
42
scripts/switch.nuget.or.project.csx
Normal file
@ -0,0 +1,42 @@
|
||||
using System.Text.RegularExpressions;
|
||||
string input = string.Empty;
|
||||
while (!new[] { "1", "2" }.Contains(input))
|
||||
{
|
||||
Console.WriteLine("1.nuget 2.project");
|
||||
input = Console.ReadLine();
|
||||
}
|
||||
var slnFile = Directory.GetFiles(@"../", "*.sln").First();
|
||||
var csprojFiles = Directory.GetFiles(@"../src", "*.csproj", new EnumerationOptions { RecurseSubdirectories = true });
|
||||
var slnContent = File.ReadAllText(slnFile);
|
||||
|
||||
if (input == "1")
|
||||
{
|
||||
slnContent = Regex.Replace(slnContent, "\\nProject\\((.*)#refs", "\n##Project($1#refs");
|
||||
slnContent = Regex.Replace(slnContent, "\\nEndProject#refs", "\n##EndProject#refs");
|
||||
foreach (Match m in Regex.Matches(slnContent, "\"(\\{[A-Z0-9]{8}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{12}\\})\"#refs"))
|
||||
{
|
||||
slnContent = slnContent.Replace($" {m.Groups[1].Value}.", $" ##{m.Groups[1].Value}.");
|
||||
}
|
||||
foreach (var csprojFile in csprojFiles)
|
||||
{
|
||||
var csprojContent = File.ReadAllText(csprojFile);
|
||||
csprojContent = Regex.Replace(csprojContent," <ProjectReference(.*)Label=\"refs\"(.*)>", " <!--<ProjectReference$1Label=\"refs\"$2>-->");
|
||||
csprojContent = Regex.Replace(csprojContent," <!--<PackageReference(.*)Label=\"refs\"(.*)>-->", " <PackageReference$1Label=\"refs\"$2>");
|
||||
File.WriteAllText(csprojFile, csprojContent);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
slnContent = Regex.Replace(slnContent, "##", "");
|
||||
foreach (var csprojFile in csprojFiles)
|
||||
{
|
||||
var csprojContent = File.ReadAllText(csprojFile);
|
||||
csprojContent = Regex.Replace(csprojContent," <!--<ProjectReference(.*)Label=\"refs\"(.*)>-->", " <ProjectReference$1Label=\"refs\"$2>");
|
||||
csprojContent = Regex.Replace(csprojContent," <PackageReference(.*)Label=\"refs\"(.*)>", " <!--<PackageReference$1Label=\"refs\"$2>-->");
|
||||
File.WriteAllText(csprojFile, csprojContent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Console.WriteLine(slnContent);
|
||||
File.WriteAllText(slnFile, slnContent);
|
@ -1,22 +0,0 @@
|
||||
{
|
||||
"solution": "NetAdmin.sln",
|
||||
"mappings": {
|
||||
"FreeSql.NS": "../refs/FreeSql/FreeSql/FreeSql.csproj",
|
||||
"FreeSql.DbContext.NS": "../refs/FreeSql/FreeSql.DbContext/FreeSql.DbContext.csproj"
|
||||
},
|
||||
"restore": [
|
||||
{
|
||||
"name": "NetAdmin.Infrastructure",
|
||||
"packages": [
|
||||
{
|
||||
"packageName": "FreeSql.NS",
|
||||
"version": "3.2.833-ns4"
|
||||
},
|
||||
{
|
||||
"packageName": "FreeSql.DbContext.NS",
|
||||
"version": "3.2.833-ns4"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
{
|
||||
"solution": "NetAdmin.sln",
|
||||
"mappings": {
|
||||
"Gurion": "../refs/Gurion/src/Gurion.csproj"
|
||||
},
|
||||
"restore": [
|
||||
{
|
||||
"name": "NetAdmin.Infrastructure",
|
||||
"packages": [
|
||||
{
|
||||
"packageName": "Gurion",
|
||||
"version": "1.1.0"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
{
|
||||
"solution": "NetAdmin.sln",
|
||||
"mappings": {
|
||||
"NSExt": "../refs/ns-ext/src/NSExt/NSExt.csproj"
|
||||
},
|
||||
"restore": [
|
||||
{
|
||||
"name": "NetAdmin.Infrastructure",
|
||||
"packages": [
|
||||
{
|
||||
"packageName": "NSExt",
|
||||
"version": "2.2.0"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
# https://github.com/RicoSuter/DNT#switch-to-projects
|
||||
$targets = @{
|
||||
'1' = 'switch-to-projects'
|
||||
'2' = 'switch-to-packages'
|
||||
}
|
||||
$key = ''
|
||||
while ($null -eq $targets[$key])
|
||||
{
|
||||
$key = Read-Host '请选择:1(切换到项目引用) 2(切换到Nuget包引用)'
|
||||
}
|
||||
$files = Get-ChildItem Switcher.*.json
|
||||
$file = 9999
|
||||
while ($null -eq $files[[int]$file - 1])
|
||||
{
|
||||
$i = 0
|
||||
Write-Host '请选择要切换的配置文件文件'
|
||||
foreach ($file in $files)
|
||||
{
|
||||
$i++
|
||||
Write-Host $i $file.Name
|
||||
}
|
||||
$file = Read-Host
|
||||
}
|
||||
$file = [int]$file - 1
|
||||
Copy-Item $files[$file] 'switcher.json' -Force
|
||||
dnt $targets[$key] ../NetAdmin.sln
|
||||
Remove-Item switcher.json
|
Reference in New Issue
Block a user