Pao*_*o B 12 git bitbucket azure libgit2sharp
我想将文件从Azure App Service上的文件夹推送到Git存储库.
我已将本地git repo复制到服务器,我使用LibGit2Sharp提交并推送这些文件:
using (var repo = new Repository(@"D:\home\site\wwwroot\repo"))
{
// Stage the file
Commands.Stage(repo, "*");
// Create the committer's signature and commit
Signature author = new Signature("translator", "example.com", DateTime.Now);
Signature committer = author;
// Commit to the repository
Commit commit = repo.Commit($"Files updated {DateTime.Now}", author, committer);
Remote remote = repo.Network.Remotes["origin"];
var options = new PushOptions
{
CredentialsProvider = (_url, _user, _cred) =>
new UsernamePasswordCredentials
{
Username = _settings.UserName,
Password = _settings.Password
}
};
repo.Network.Push(remote, @"+refs/heads/master", options);
}
Run Code Online (Sandbox Code Playgroud)
它工作,但似乎需要一段时间,这似乎有点笨重.有没有更有效的方法通过代码实现这一点,或者可能直接通过Azure(配置或Azure功能)?
对于Azure应用程序,您仍然可以捆绑嵌入式exes,下面的链接上有一个便携式Git
https://github.com/sheabunge/GitPortable
您应该将其与您的应用捆绑在一起并创建批处理文件.然后你应该使用C#代码启动它
static void ExecuteCommand(string command)
{
var processInfo = new ProcessStartInfo("cmd.exe", "/c " + command);
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;
processInfo.RedirectStandardError = true;
processInfo.RedirectStandardOutput = true;
var process = Process.Start(processInfo);
process.OutputDataReceived += (object sender, DataReceivedEventArgs e) =>
Console.WriteLine("output>>" + e.Data);
process.BeginOutputReadLine();
process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) =>
Console.WriteLine("error>>" + e.Data);
process.BeginErrorReadLine();
process.WaitForExit();
Console.WriteLine("ExitCode: {0}", process.ExitCode);
process.Close();
}
Run Code Online (Sandbox Code Playgroud)
PS:在C#中执行批处理文件的积分
另一个谈论类似事情的SO线程
Azure App Service,运行本机EXE以转换文件
| 归档时间: |
|
| 查看次数: |
529 次 |
| 最近记录: |