Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (5)
Tags (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
Branches (5)
Tags (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
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (5)
Tags (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.CustomTool
/
ScriptyGenerator.cs
Scripty
/
src
/
Scripty.CustomTool
/
ScriptyGenerator.cs
ScriptyGenerator.cs 4.47 KB
Copy Edit Raw Blame History
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using EnvDTE;
using Microsoft.VisualStudio.Shell;
using Scripty.Core;
using Scripty.Core.Output;
namespace Scripty
{
/// <summary>
/// This is the generator class.
/// When setting the 'Custom Tool' property of a C# or VB project item to "Scripty",
/// the GenerateCode function will get called and will return the contents of the generated file
/// to the project system
/// </summary>
[ComVisible(true)]
[Guid("1B8589A2-58FF-4413-9EA3-A66A1605F1E4")]
[CodeGeneratorRegistration(typeof(ScriptyGenerator), "C# Scripty Generator", "{FAE04EC1-301F-11D3-BF4B-00C04F79EFBC}", GeneratesDesignTimeSource = true)]
[CodeGeneratorRegistration(typeof(ScriptyGenerator), "VB.NET Scripty Generator", "{164B10B9-B200-11D0-8C61-00A0C91E29D5}", GeneratesDesignTimeSource = true)]
[ProvideObject(typeof(ScriptyGenerator))]
public class ScriptyGenerator : BaseCodeGeneratorWithSite
{
#pragma warning disable 0414, 169
//The name of this generator (use for 'Custom Tool' property of project item)
// ReSharper disable once InconsistentNaming
internal static string name = "ScriptyGenerator";
#pragma warning restore 0414, 169
protected override string GetDefaultExtension()
{
return ".log";
}
/// <summary>
/// Function that builds the contents of the generated file based on the contents of the input file.
/// </summary>
/// <param name="inputFileContent">Content of the input file</param>
/// <returns>Generated file as a byte array</returns>
protected override byte[] GenerateCode(string inputFileContent)
{
// Some good examples: https://t4toolbox.svn.codeplex.com/svn/Source/DteProcessor.cs
// And https://github.com/madskristensen/ExtensibilityTools/blob/master/src/VsixManifest/Generator/ResxFileGenerator.cs
try
{
ProjectItem projectItem = GetProjectItem();
string inputFilePath = projectItem.Properties.Item("FullPath").Value.ToString();
Project project = projectItem.ContainingProject;
Solution solution = projectItem.DTE.Solution;
// Run the generator and get the results
ScriptSource source = new ScriptSource(inputFilePath, inputFileContent);
ScriptEngine engine = new ScriptEngine(project.FullName, solution.FullName, null);
ScriptResult result = engine.Evaluate(source).Result;
// Report errors
if (result.Errors.Count > 0)
{
foreach (ScriptError error in result.Errors)
{
GeneratorError(4, error.Message, (uint) error.Line, (uint) error.Column);
}
return null;
}
// Add generated files to the project
foreach (IOutputFileInfo outputFile in result.OutputFiles.Where(x => x.BuildAction != BuildAction.GenerateOnly))
{
ProjectItem outputItem = projectItem.ProjectItems.Cast<ProjectItem>()
.FirstOrDefault(x => x.Properties.Item("FullPath")?.Value?.ToString() == outputFile.FilePath)
?? projectItem.ProjectItems.AddFromFile(outputFile.FilePath);
outputItem.Properties.Item("ItemType").Value = outputFile.BuildAction.ToString();
}
// Remove/delete files from the last generation but not in this one
string logPath = Path.ChangeExtension(inputFilePath, ".log");
if (File.Exists(logPath))
{
string[] logLines = File.ReadAllLines(logPath);
foreach (string fileToRemove in logLines.Where(x => result.OutputFiles.All(y => y.FilePath != x)))
{
solution.FindProjectItem(fileToRemove)?.Delete();
}
}
// Create the log file
return Encoding.UTF8.GetBytes(string.Join(Environment.NewLine, result.OutputFiles.Select(x => x.FilePath)));
}
catch (Exception ex)
{
GeneratorError(4, ex.ToString(), 0, 0);
return null;
}
}
}
}
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

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

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

取消
提交

Releases

No release

Contributors

All

Language(Optional)

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/MicroDistanceStudio/Scripty.git
git@gitee.com:MicroDistanceStudio/Scripty.git
MicroDistanceStudio
Scripty
Scripty
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

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