Skip to content
Permalink
Browse files

Fixed zip search and replace process in build script.

  • Loading branch information
dotnetjunkie committed Nov 30, 2019
1 parent 628dbea commit 8b7cbd007a5053f93f963e65939cef67f4ced005
Showing with 21 additions and 26 deletions.
  1. +16 −21 src/BuildTools/zipreplace.cs
  2. BIN src/BuildTools/zipreplace.exe
  3. +5 −5 src/build.bat
@@ -20,8 +20,8 @@ private static void Main(string[] args)
"[/zipTarget:target.zip] " +
"/source:source.txt " +
"[/target:target.txt] " +
"\"search text\" " +
"\"replacement text\" " +
"\"/search:search text\" " +
"\"/replace:replacement text\" " +
"[/force] " +
"[/line]");
return;
@@ -34,6 +34,9 @@ private static void Main(string[] args)
if (arguments.InvalidArguments.Any())
ExitWithMessage("Invalid arguments found.", arguments);

if (string.IsNullOrEmpty(arguments.SearchText))
ExitWithMessage("No search text supplied.", arguments);

if (string.IsNullOrWhiteSpace(arguments.ZipSource))
ExitWithMessage("/zipSource not supplied.", arguments);

@@ -149,32 +152,21 @@ private static void ExitWithMessage(string message, Arguments arguments)

private static Arguments GetArguments(string[] args)
{
string zipSource = args.SingleOrDefault(a => a.StartsWith("/zipSource:"))
?.Substring("/zipSource:".Length);

string zipTarget = args.SingleOrDefault(a => a.StartsWith("/zipTarget:"))
?.Substring("/zipTarget:".Length) ?? zipSource;

string sourceFile = args.SingleOrDefault(a => a.StartsWith("/sourceFile:"))
?.Substring("/sourceFile:".Length);

string targetFile = args.SingleOrDefault(a => a.StartsWith("/targetFile:"))
?.Substring("/targetFile:".Length) ?? sourceFile;

return new Arguments
{
ZipSource = zipSource,
ZipTarget = zipTarget,
SourceFile = sourceFile,
TargetFile = targetFile,
SearchText = args.First(a => !a.StartsWith("/")),
ReplaceText = args.Last(a => !a.StartsWith("/")),
ZipSource = GetValue("zipSource", args),
ZipTarget = GetValue("zipTarget", args) ?? GetValue("zipSource", args),
SourceFile = GetValue("sourceFile", args),
TargetFile = GetValue("targetFile", args) ?? GetValue("sourceFile", args),
SearchText = GetValue("search", args),
ReplaceText = GetValue("replace", args),
ReplaceCompleteLine = args.Any(a => a == "/line"),
ForceReplace = args.Any(a => a == "/force"),
IncludeStackTrace = args.Any(a => a == "/stackTrace"),
InvalidArguments = (
from arg in args
where arg.StartsWith("/")
where !arg.StartsWith("/search:")
where !arg.StartsWith("/replace:")
where !arg.StartsWith("/zipSource:")
where !arg.StartsWith("/zipTarget:")
where !arg.StartsWith("/sourceFile:")
@@ -185,6 +177,9 @@ where arg.StartsWith("/")
};
}

private static string GetValue(string tag, string[] args) =>
args.SingleOrDefault(a => a.StartsWith($"/{tag}:"))?.Substring($"/{tag}:".Length);

class Arguments
{
public string ZipSource { get; set; }
BIN +0 Bytes (100%) src/BuildTools/zipreplace.exe
Binary file not shown.
@@ -342,19 +342,19 @@ IF %step%==4 (
set coreLibraryNupkgDependencyReplace="<dependency id=""SimpleInjector"" version=""[%named_version_Core%,%nextMajorVersion%)"""

copy "SimpleInjector.Integration.ServiceCollection\bin\Release\SimpleInjector.Integration.ServiceCollection.%named_version_Integration_ServiceCollection%.nupkg" Releases\v%named_version%\
%zipreplace% /zipSource:Releases\v%named_version%\SimpleInjector.Integration.ServiceCollection.%named_version_Integration_ServiceCollection%.nupkg /sourceFile:SimpleInjector.Integration.ServiceCollection.nuspec %coreLibraryNupkgDependencySearch% %coreLibraryNupkgDependencyReplace% /force
%zipreplace% /zipSource:Releases\v%named_version%\SimpleInjector.Integration.ServiceCollection.%named_version_Integration_ServiceCollection%.nupkg /sourceFile:SimpleInjector.Integration.ServiceCollection.nuspec /search:%coreLibraryNupkgDependencySearch% /replace:%coreLibraryNupkgDependencyReplace% /force

copy "SimpleInjector.Integration.GenericHost\bin\Release\SimpleInjector.Integration.GenericHost.%named_version_Integration_GenericHost%.nupkg" Releases\v%named_version%\
%zipreplace% /zipSource:Releases\v%named_version%\SimpleInjector.Integration.GenericHost.%named_version_Integration_GenericHost%.nupkg /sourceFile:SimpleInjector.Integration.GenericHost.nuspec %coreLibraryNupkgDependencySearch% %coreLibraryNupkgDependencyReplace% /force
%zipreplace% /zipSource:Releases\v%named_version%\SimpleInjector.Integration.GenericHost.%named_version_Integration_GenericHost%.nupkg /sourceFile:SimpleInjector.Integration.GenericHost.nuspec /search:%coreLibraryNupkgDependencySearch% /replace:%coreLibraryNupkgDependencyReplace% /force

copy "SimpleInjector.Integration.AspNetCore\bin\Release\SimpleInjector.Integration.AspNetCore.%named_version_Integration_AspNetCore%.nupkg" Releases\v%named_version%\
%zipreplace% /zipSource:Releases\v%named_version%\SimpleInjector.Integration.AspNetCore.%named_version_Integration_AspNetCore%.nupkg /sourceFile:SimpleInjector.Integration.AspNetCore.nuspec %coreLibraryNupkgDependencySearch% %coreLibraryNupkgDependencyReplace% /force
%zipreplace% /zipSource:Releases\v%named_version%\SimpleInjector.Integration.AspNetCore.%named_version_Integration_AspNetCore%.nupkg /sourceFile:SimpleInjector.Integration.AspNetCore.nuspec /search:%coreLibraryNupkgDependencySearch% /replace:%coreLibraryNupkgDependencyReplace% /force

copy "SimpleInjector.Integration.AspNetCore.Mvc.Core\bin\Release\SimpleInjector.Integration.AspNetCore.Mvc.Core.%named_version_Integration_AspNetCore_Mvc_Core%.nupkg" Releases\v%named_version%\
%zipreplace% /zipSource:Releases\v%named_version%\SimpleInjector.Integration.AspNetCore.Mvc.Core.%named_version_Integration_AspNetCore_Mvc_Core%.nupkg /sourceFile:SimpleInjector.Integration.AspNetCore.Mvc.Core.nuspec %coreLibraryNupkgDependencySearch% %coreLibraryNupkgDependencyReplace%
%zipreplace% /zipSource:Releases\v%named_version%\SimpleInjector.Integration.AspNetCore.Mvc.Core.%named_version_Integration_AspNetCore_Mvc_Core%.nupkg /sourceFile:SimpleInjector.Integration.AspNetCore.Mvc.Core.nuspec /search:%coreLibraryNupkgDependencySearch% /replace:%coreLibraryNupkgDependencyReplace%

copy "SimpleInjector.Integration.AspNetCore.Mvc\bin\Release\SimpleInjector.Integration.AspNetCore.Mvc.%named_version_Integration_AspNetCore_Mvc%.nupkg" Releases\v%named_version%\
%zipreplace% /zipSource:Releases\v%named_version%\SimpleInjector.Integration.AspNetCore.Mvc.%named_version_Integration_AspNetCore_Mvc%.nupkg /sourceFile:SimpleInjector.Integration.AspNetCore.Mvc.nuspec %coreLibraryNupkgDependencySearch% %coreLibraryNupkgDependencyReplace%
%zipreplace% /zipSource:Releases\v%named_version%\SimpleInjector.Integration.AspNetCore.Mvc.%named_version_Integration_AspNetCore_Mvc%.nupkg /sourceFile:SimpleInjector.Integration.AspNetCore.Mvc.nuspec /search:%coreLibraryNupkgDependencySearch% /replace:%coreLibraryNupkgDependencyReplace%

echo Please run step 5
goto :EOF

0 comments on commit 8b7cbd0

Please sign in to comment.
You can’t perform that action at this time.