开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (5)
标签 (11)
master
dependabot/nuget/src/Scripty.MsBuild/Newtonsoft.Json-13.0.2
dependabot/nuget/src/Scripty/Newtonsoft.Json-13.0.2
develop
reboot
v0.7.4
v0.7.3
v0.7.2
v0.7.1
v0.7.0
v0.6.0
v0.5.0
v0.4.0
v0.3.0
v0.2.0
v0.1.0-beta
master
分支 (5)
标签 (11)
master
dependabot/nuget/src/Scripty.MsBuild/Newtonsoft.Json-13.0.2
dependabot/nuget/src/Scripty/Newtonsoft.Json-13.0.2
develop
reboot
v0.7.4
v0.7.3
v0.7.2
v0.7.1
v0.7.0
v0.6.0
v0.5.0
v0.4.0
v0.3.0
v0.2.0
v0.1.0-beta
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (5)
标签 (11)
master
dependabot/nuget/src/Scripty.MsBuild/Newtonsoft.Json-13.0.2
dependabot/nuget/src/Scripty/Newtonsoft.Json-13.0.2
develop
reboot
v0.7.4
v0.7.3
v0.7.2
v0.7.1
v0.7.0
v0.6.0
v0.5.0
v0.4.0
v0.3.0
v0.2.0
v0.1.0-beta
Scripty
/
src
/
Scripty.MsBuild
/
ScriptyTask.cs
Scripty
/
src
/
Scripty.MsBuild
/
ScriptyTask.cs
ScriptyTask.cs 8.66 KB
一键复制 编辑 原始数据 按行查看 历史
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Newtonsoft.Json;
namespace Scripty.MsBuild
{
public class ScriptyTask : Microsoft.Build.Utilities.Task
{
private readonly List<ITaskItem> _noneFiles = new List<ITaskItem>();
private readonly List<ITaskItem> _compileFiles = new List<ITaskItem>();
private readonly List<ITaskItem> _contentFiles = new List<ITaskItem>();
private readonly List<ITaskItem> _embeddedResourceFiles = new List<ITaskItem>();
[Required]
public string ProjectFilePath { get; set; }
public string SolutionFilePath { get; set; }
public string ScriptyExecutable { get; set; }
public ITaskItem[] ScriptFiles { get; set; }
[Output]
public ITaskItem[] NoneFiles => _noneFiles.ToArray();
[Output]
public ITaskItem[] CompileFiles => _compileFiles.ToArray();
[Output]
public ITaskItem[] ContentFiles => _contentFiles.ToArray();
[Output]
public ITaskItem[] EmbeddedResourceFiles => _embeddedResourceFiles.ToArray();
public override bool Execute()
{
if (ScriptFiles == null || ScriptFiles.Length == 0)
{
return true;
}
if (string.IsNullOrEmpty(ProjectFilePath))
{
Log.LogError("A project file is required");
return false;
}
if (!Path.IsPathRooted(ProjectFilePath))
{
Log.LogError("The project file path must be absolute");
return false;
}
if (string.IsNullOrEmpty(ScriptyExecutable))
{
ScriptyExecutable = Path.Combine(Path.GetDirectoryName(typeof(ScriptyTask).Assembly.Location), "Scripty.exe");
}
if (!File.Exists(ScriptyExecutable))
{
Log.LogError($"Scripty executable not found at '{ScriptyExecutable}'.");
return false;
}
// Kick off the evaluation process, which must be done in a seperate process space
// otherwise MSBuild complains when we construct the Roslyn workspace project since
// it uses MSBuild to figure out what the project contains and MSBuild only supports
// one build per process
Log.LogMessage("Starting out-of-process script evaluation...");
List<string> outputData = new List<string>();
List<string> errorData = new List<string>();
Process process = new Process();
process.StartInfo.FileName = ScriptyExecutable;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardInput = true;
process.OutputDataReceived += (s, e) => outputData.Add(e.Data);
process.ErrorDataReceived += (s, e) => errorData.Add(e.Data);
process.Start();
// Create and send the settings
string settingsJson = GetSettingsJson();
process.StandardInput.Write(settingsJson);
process.StandardInput.Flush();
process.StandardInput.Close();
// Wait for the process to exit
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
if (process.ExitCode == 0)
{
Log.LogMessage("Finished script evaluation");
}
else
{
Log.LogError("Got non-zero exit code from script evaluation: " + process.ExitCode);
}
// Report any errors
foreach (string error in errorData.Where(x => !string.IsNullOrWhiteSpace(x)))
{
Log.LogError(error);
return false;
}
// Add the compile files
List<Tuple<BuildAction, string>> outputFiles = outputData
.Where(x => !string.IsNullOrWhiteSpace(x))
.Select(x => x.Split('|'))
.Where(x => x.Length == 2 && !string.IsNullOrWhiteSpace(x[0]) && !string.IsNullOrWhiteSpace(x[1]))
.Select(x =>
{
BuildAction buildAction;
if (!Enum.TryParse(x[0], out buildAction))
{
buildAction = BuildAction.GenerateOnly;
}
return new Tuple<BuildAction, string>(buildAction, x[1]);
})
.Where(x => x.Item1 != BuildAction.GenerateOnly)
.ToList();
Log.LogMessage("Output file count: " + outputFiles.Count);
_noneFiles.AddRange(outputFiles
.Where(x => x.Item1 == BuildAction.None)
.Select(x =>
{
TaskItem taskItem = new TaskItem(x.Item2);
taskItem.SetMetadata("AutoGen", "true");
return taskItem;
}));
_compileFiles.AddRange(outputFiles
.Where(x => x.Item1 == BuildAction.Compile)
.Select(x =>
{
TaskItem taskItem = new TaskItem(x.Item2);
taskItem.SetMetadata("AutoGen", "true");
return taskItem;
}));
_contentFiles.AddRange(outputFiles
.Where(x => x.Item1 == BuildAction.Content)
.Select(x =>
{
TaskItem taskItem = new TaskItem(x.Item2);
taskItem.SetMetadata("AutoGen", "true");
return taskItem;
}));
_embeddedResourceFiles.AddRange(outputFiles
.Where(x => x.Item1 == BuildAction.EmbeddedResource)
.Select(x =>
{
TaskItem taskItem = new TaskItem(x.Item2);
taskItem.SetMetadata("AutoGen", "true");
return taskItem;
}));
return !Log.HasLoggedErrors;
}
private string GetSettingsJson()
{
Settings settings = new Settings
{
ProjectFilePath = ProjectFilePath,
Properties = GetMsBuildProperties(),
ScriptFilePaths = ScriptFiles
.Select(x => x.GetMetadata("FullPath"))
.Where(x => !string.IsNullOrEmpty(x))
.Distinct()
.ToList(),
SolutionFilePath = SolutionFilePath?.Contains("*Undefined*") == true ? null : SolutionFilePath
};
return JsonConvert.SerializeObject(settings);
}
private IDictionary<string, string> GetMsBuildProperties()
{
// We need to use reflection to get
// the build properties out of MSBuild.
try
{
int version = BuildEngine.GetType().Assembly.GetName().Version.Major;
// The name of the field that stores the IBuildComponentHost changed in MSBuild 14.
object host = BuildEngine.GetType().InvokeMember(
(version >= 14) ? "_host" : "host",
BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Instance,
null,
BuildEngine,
new object[] { }
);
object buildParameters = host.GetType().GetInterface("IBuildComponentHost").InvokeMember(
"BuildParameters",
BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance,
null,
host,
new object[] { }
);
object globalProperties = buildParameters.GetType().InvokeMember(
"GlobalProperties",
BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance,
null,
buildParameters,
new object[] { }
);
return (IDictionary<string, string>)globalProperties;
}
catch (Exception ex)
{
Log.LogWarning("Could not get global properties from MSBuild: " + ex.Message);
return null;
}
}
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/MicroDistanceStudio/Scripty.git
git@gitee.com:MicroDistanceStudio/Scripty.git
MicroDistanceStudio
Scripty
Scripty
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /