本文整理汇总了C#中Project.GetProjectItem方法的典型用法代码示例。如果您正苦于以下问题:C# Project.GetProjectItem方法的具体用法?C# Project.GetProjectItem怎么用?C# Project.GetProjectItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Project
的用法示例。
在下文中一共展示了Project.GetProjectItem方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveProjectConfig
private void SaveProjectConfig(Project project, XmlScaffoldingConfig config)
{
var projectConfigItem = project.GetProjectItem(ConfigXmlFilename);
if (projectConfigItem != null)
SaveConfigToFile(projectConfigItem.GetFullPath(), config);
else {
var outputFilename = Path.Combine(project.GetFullPath(), ConfigXmlFilename);
SaveConfigToFile(outputFilename, config);
project.ProjectItems.AddFromFile(outputFilename);
}
}
示例2: GetScaffolders
public IEnumerable<ScaffolderInfo> GetScaffolders(Project project, string name, bool resolveDefaultNames)
{
var customScaffoldersFolder = project != null ? project.GetProjectItem(ScaffoldingConstants.CustomScaffoldersFolderPath) : null;
var customScaffoldersFolders = customScaffoldersFolder != null ? new[] { customScaffoldersFolder } : Enumerable.Empty<ProjectItem>();
var allPackages = _packageManager.LocalRepository.GetPackages();
var packagesWithToolsPath = from p in allPackages
let installPath = _pathResolver.GetInstallPath(p)
where !string.IsNullOrEmpty(installPath)
select new {
Package = p,
ToolsPath = Path.Combine(installPath, "tools")
};
// Only consider the single latest version of any given package
var latestPackagesWithToolsPath = from packageGroup in packagesWithToolsPath.GroupBy(x => x.Package.Id)
select packageGroup.OrderByDescending(x => x.Package.Version).First();
// Note that we prefer to match actual scaffolder names (rather than resolving default names first)
// so that you can't "override" a scaffolder by creating a default with the same name. Allowing that
// could lead to unexpected behavior, especially if such a default was created by mistake.
var actualMatches = latestPackagesWithToolsPath.SelectMany(x => FindScaffolders(x.Package, x.ToolsPath, name))
.Concat(customScaffoldersFolders.SelectMany(x => FindScaffolders(x, name)));
if (actualMatches.Any())
return actualMatches;
// Since no scaffolders actually match "name", try resolving that as a default name and go again
if (resolveDefaultNames) {
// First look for a project-specific setting, and if not found, fall back on solution-wide settings
IQueryable<DefaultScaffolderConfigEntry> resolvedNames = null;
if (project != null)
resolvedNames = _configStore.GetProjectDefaultScaffolders(project).Where(x => x.DefaultName.Equals(name, StringComparison.OrdinalIgnoreCase));
if ((resolvedNames == null) || (!resolvedNames.Any()))
resolvedNames = _configStore.GetSolutionDefaultScaffolders().Where(x => x.DefaultName.Equals(name, StringComparison.OrdinalIgnoreCase));
if (resolvedNames.Count() == 1) {
var resolvedName = resolvedNames.Single().ScaffolderName;
return latestPackagesWithToolsPath.SelectMany(x => FindScaffolders(x.Package, x.ToolsPath, resolvedName))
.Concat(customScaffoldersFolders.SelectMany(x => FindScaffolders(x, resolvedName)));
}
}
return Enumerable.Empty<ScaffolderInfo>();
}
示例3: GetTemplateOutput
private static TemplateRenderingResult GetTemplateOutput(Project project, IFileSystem fileSystem, string template, string projectRelativeOutputPath, Hashtable model, bool force)
{
var templateFullPath = FindTemplateAssertExists(project, fileSystem, template);
var templateContent = fileSystem.ReadAllText(templateFullPath);
templateContent = PreprocessTemplateContent(templateContent);
// Create the T4 host and engine
using (var host = new DynamicTextTemplatingEngineHost { TemplateFile = templateFullPath }) {
var t4Engine = GetT4Engine();
// Make it possible to reference the same assemblies that your project references
// using <@ Assembly @> directives.
host.AddFindableAssembly(FindProjectAssemblyIfExists(project));
foreach (dynamic reference in ((dynamic)project.Object).References) {
if ((!string.IsNullOrEmpty(reference.Path)) && (!reference.AutoReferenced))
host.AddFindableAssembly(reference.Path);
}
string projectRelativeOutputPathWithExtension = null;
ProjectItem existingOutputProjectItem = null;
if (!string.IsNullOrEmpty(projectRelativeOutputPath)) {
// Respect the <#@ Output Extension="..." #> directive
projectRelativeOutputPathWithExtension = projectRelativeOutputPath + GetOutputExtension(host, t4Engine, templateContent);
// Resolve the output path and ensure it doesn't already exist (unless "Force" is set)
var outputDiskPath = Path.Combine(project.GetFullPath(), projectRelativeOutputPathWithExtension);
existingOutputProjectItem = project.GetProjectItem(projectRelativeOutputPathWithExtension);
if (existingOutputProjectItem != null)
outputDiskPath = existingOutputProjectItem.GetFullPath();
if ((!force) && fileSystem.FileExists(outputDiskPath)) {
return new TemplateRenderingResult(projectRelativeOutputPathWithExtension) { SkipBecauseFileExists = true };
}
}
// Convert the incoming Hashtable to a dynamic object with properties for each of the Hashtable entries
host.Model = DynamicViewModel.FromObject(model);
// Run the text transformation
var templateOutput = t4Engine.ProcessTemplate(templateContent, host);
return new TemplateRenderingResult(projectRelativeOutputPathWithExtension) {
Content = templateOutput,
Errors = host.Errors,
ExistingProjectItemToOverwrite = existingOutputProjectItem,
};
}
}
示例4: FindTemplateAssertExists
private static string FindTemplateAssertExists(Project project, IFileSystem fileSystem, string template)
{
string templateFullPath = template;
if (!Path.IsPathRooted(templateFullPath)) {
var templateProjectItem = project.GetProjectItem(templateFullPath);
if (templateProjectItem != null)
templateFullPath = templateProjectItem.GetFullPath();
}
if (!fileSystem.FileExists(templateFullPath)) {
throw new FileNotFoundException(string.Format("Cannot find template at '{0}'", templateFullPath));
}
return templateFullPath;
}
示例5: LoadProjectConfig
private static XmlScaffoldingConfig LoadProjectConfig(Project project)
{
var projectConfigItem = project.GetProjectItem(ConfigXmlFilename);
return projectConfigItem != null ? LoadConfigFromFile(projectConfigItem.GetFullPath())
: new XmlScaffoldingConfig();
}
示例6: BuildSourceFile
/// <summary>
/// Builds the source file.
/// </summary>
/// <param name="project">The project.</param>
/// <param name="extensionSource">The extensionSource.</param>
/// <param name="extensionDestination">The extension destination.</param>
/// <param name="friendlyName">Name of the friendly.</param>
internal void BuildSourceFile(
Project project,
string extensionSource,
string extensionDestination,
string friendlyName)
{
try
{
const string PlaceHolderText = "#PlaceHolder#";
string message = string.Format("BuildSourceFile Project Name={0} friendlyName={1}", project.Name, friendlyName);
TraceService.WriteLine(message);
string sourceFile = friendlyName + "PluginBootstrap.cs";
//// now we need to sort out the item template!
project.AddToFolderFromTemplate("Bootstrap", "MvvmCross.Plugin.zip", sourceFile);
ProjectItem projectItem = project.GetProjectItem(sourceFile);
//// if we find the project item replace the text in it else use the find/replace window.
if (projectItem != null)
{
TextSelection textSelection = projectItem.DTE.ActiveDocument.Selection;
textSelection.SelectAll();
textSelection.ReplacePattern(PlaceHolderText, friendlyName);
projectItem.Save();
}
}
catch (Exception exception)
{
TraceService.WriteError("BuildSourceFile " + exception.Message);
}
}