本文整理汇总了C#中Microsoft.Build.Evaluation.Project类的典型用法代码示例。如果您正苦于以下问题:C# Project类的具体用法?C# Project怎么用?C# Project使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Project类属于Microsoft.Build.Evaluation命名空间,在下文中一共展示了Project类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Project
public Project(Solution solution, string title, string fileName)
{
AssembliesResolved = false;
ReferencedAssemblies = new List<string>();
CompilerSettings = new CompilerSettings();
ReferencedProjects = new List<string>();
Files = new List<File>();
Solution = solution;
Title = title;
FileName = Path.GetFullPath(fileName);
ProjectCollection.GlobalProjectCollection.UnloadAllProjects();
MsBuildProject = new Microsoft.Build.Evaluation.Project(fileName);
AssemblyName = MsBuildProject.GetPropertyValue("AssemblyName");
CompilerSettings.AllowUnsafeBlocks = MsBuildProject.GetPropertyAsBoolean("AllowUnsafeBlocks");
CompilerSettings.CheckForOverflow = MsBuildProject.GetPropertyAsBoolean("CheckForOverflowUnderflow");
var defineConstants = MsBuildProject.GetPropertyValue("DefineConstants");
foreach (string symbol in defineConstants.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
{
CompilerSettings.ConditionalSymbols.Add(symbol.Trim());
}
foreach (var sourceCodeFile in MsBuildProject.GetItems("Compile"))
{
Files.Add(new File(this, Path.Combine(MsBuildProject.DirectoryPath, sourceCodeFile.EvaluatedInclude)));
}
foreach (var projectReference in MsBuildProject.GetItems("ProjectReference"))
{
string referencedFileName = Path.GetFullPath(Path.Combine(MsBuildProject.DirectoryPath, projectReference.EvaluatedInclude));
ReferencedProjects.Add(referencedFileName);
}
}
开发者ID:rpepato,项目名称:StructEx,代码行数:35,代码来源:Project.cs
示例2: AddEnsureImportedTarget
private static void AddEnsureImportedTarget(MicrosoftBuildEvaluationProject msBuildProject, string targetsPath)
{
// get the target
var targetElement = msBuildProject.Xml.Targets.FirstOrDefault(
target => target.Name.Equals(targetName, StringComparison.OrdinalIgnoreCase));
// if the target does not exist, create the target
if (targetElement == null)
{
targetElement = msBuildProject.Xml.AddTarget(targetName);
// PrepareForBuild is used here because BeforeBuild does not work for VC++ projects.
targetElement.BeforeTargets = "PrepareForBuild";
var propertyGroup = targetElement.AddPropertyGroup();
propertyGroup.AddProperty("ErrorText", CommonResources.EnsureImportedMessage);
}
var errorTask = targetElement.AddTask("Error");
errorTask.Condition = "!Exists('" + targetsPath + "')";
var errorText = string.Format(
CultureInfo.InvariantCulture,
@"$([System.String]::Format('$(ErrorText)', '{0}'))",
targetsPath);
errorTask.SetParameter("Text", errorText);
}
开发者ID:mauroa,项目名称:NuGet.VisualStudioExtension,代码行数:26,代码来源:MicrosoftBuildEvaluationProjectUtility.cs
示例3: CreateBuildProject
void CreateBuildProject()
{
string projectPath = Path.Combine(buildDirectory, "content.contentproj");
string outputPath = Path.Combine(buildDirectory, "bin");
// Create the build project.
projectRootElement = ProjectRootElement.Create(projectPath);
// Include the standard targets file that defines how to build XNA Framework content.
projectRootElement.AddImport(Application.StartupPath + "\\Exporters\\FBX\\XNA\\XNA Game Studio\\" +
"v4.0\\Microsoft.Xna.GameStudio.ContentPipeline.targets");
buildProject = new Project(projectRootElement);
buildProject.SetProperty("XnaPlatform", "Windows");
buildProject.SetProperty("XnaProfile", "Reach");
buildProject.SetProperty("XnaFrameworkVersion", "v4.0");
buildProject.SetProperty("Configuration", "Release");
buildProject.SetProperty("OutputPath", outputPath);
buildProject.SetProperty("ContentRootDirectory", ".");
buildProject.SetProperty("ReferencePath", Application.StartupPath);
// Register any custom importers or processors.
foreach (string pipelineAssembly in pipelineAssemblies)
{
buildProject.AddItem("Reference", pipelineAssembly);
}
// Hook up our custom error logger.
errorLogger = new ErrorLogger();
buildParameters = new BuildParameters(ProjectCollection.GlobalProjectCollection)
{Loggers = new ILogger[] {errorLogger}};
}
开发者ID:nicolasmassouh,项目名称:Babylon.js,代码行数:34,代码来源:ContentBuilder.cs
示例4: SetDefaultToolsVersion
public void SetDefaultToolsVersion()
{
string oldValue = Environment.GetEnvironmentVariable("MSBUILDLEGACYDEFAULTTOOLSVERSION");
try
{
// In the new world of figuring out the ToolsVersion to use, we completely ignore the default
// ToolsVersion in the ProjectCollection. However, this test explicitly depends on modifying
// that, so we need to turn the new defaulting behavior off in order to verify that this still works.
Environment.SetEnvironmentVariable("MSBUILDLEGACYDEFAULTTOOLSVERSION", "1");
InternalUtilities.RefreshInternalEnvironmentValues();
ProjectCollection collection = new ProjectCollection();
collection.AddToolset(new Toolset("x", @"c:\y", collection, null));
collection.DefaultToolsVersion = "x";
Assert.AreEqual("x", collection.DefaultToolsVersion);
string content = @"
<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' >
<Target Name='t'/>
</Project>
";
Project project = new Project(XmlReader.Create(new StringReader(content)), null, null, collection);
Assert.AreEqual(project.ToolsVersion, "x");
}
finally
{
Environment.SetEnvironmentVariable("MSBUILDLEGACYDEFAULTTOOLSVERSION", oldValue);
InternalUtilities.RefreshInternalEnvironmentValues();
}
}
开发者ID:JamesLinus,项目名称:msbuild,代码行数:35,代码来源:Project_Internal_Tests.cs
示例5: ProjectGetter
public void ProjectGetter()
{
Project project = new Project();
ProjectItem item = project.AddItem("i", "i1")[0];
Assert.Equal(true, Object.ReferenceEquals(project, item.Project));
}
开发者ID:nikson,项目名称:msbuild,代码行数:7,代码来源:ProjectItem_Tests.cs
示例6: generate
internal static void generate(string filename, string version, string asmName, string ns, ProjectType type)
{
Project p = new Project();
string typeDesc = null;
p.Xml.DefaultTargets = "Build";
createItemGroup(p, "ProjectConfigurations");
createGlobals(ns, type, p, "Globals");
p.Xml.AddImport(@"$(VCTargetsPath)\Microsoft.Cpp.Default.props");
switch (type) {
case ProjectType.ConsoleApp: typeDesc = "Application"; break;
case ProjectType.XamlApp: typeDesc = "Application"; break;
case ProjectType.ClassLibrary: typeDesc = "DynamicLibrary"; break;
default:
throw new InvalidOperationException("unhandled projectType: " + type);
}
createCfgProp(p.Xml, typeDesc, true);
createCfgProp(p.Xml, typeDesc, false);
p.Xml.AddImport(@"$(VCTargetsPath)\Microsoft.Cpp.props");
addPropertySheetImports(p.Xml);
addPropertyGroup(p.Xml, makeCfgCondition(DEBUG, PLATFORM), new Blah2(b2));
addPropertyGroup(p.Xml, makeCfgCondition(RELEASE, PLATFORM), new Blah2(b2));
addItemDefs(p.Xml);
const string C_TARGET_RULES = @"$(VCTargetsPath)\Microsoft.Cpp.targets";
var v99 = p.Xml.CreateImportElement(C_TARGET_RULES);
p.Xml.AppendChild(v99);
p.Save(filename);
}
开发者ID:surak8,项目名称:ProjectGen,代码行数:30,代码来源:CProjectGenerator.cs
示例7: ProjectGetter
public void ProjectGetter()
{
Project project = new Project();
ProjectProperty property = project.SetProperty("p", "v");
Assert.Equal(true, Object.ReferenceEquals(project, property.Project));
}
开发者ID:cameron314,项目名称:msbuild,代码行数:7,代码来源:ProjectProperty_Tests.cs
示例8: generateFiles
internal static void generateFiles(Project p, PGOptions opts1, ProjectItemGroupElement pige)
{
Dictionary<string, string> tmp = new Dictionary<string, string>();
WinDataProvider wdp = new WinDataProvider(WIN_NAME, opts1.projectNamespace, opts1.xamlType == XamlWindowType.RegularWindow);
AppDataProvider apd = new AppDataProvider(wdp.fileName, opts1.projectNamespace);
HomeDataProvider hdp = null;
string tmp2;
XamlFileGenerator.generateFile(apd, opts1);
XamlFileGenerator.generateFile(wdp, opts1);
if (opts1.xamlType == XamlWindowType.NavigationWindow) {
hdp = new HomeDataProvider(wdp.homePage, opts1.projectNamespace);
XamlFileGenerator.generateFile(hdp, opts1);
generatePageAndModel(pige, hdp);
}
if (!string.IsNullOrEmpty(tmp2 = wdp.viewModelName) && File.Exists(tmp2)) {
generateCompile(pige, tmp2);
}
generateApp(pige, apd);
generatePage(pige, wdp);
if (opts1.xamlPages.Count > 0) {
GeneralPage gp;
foreach (string aPageName in opts1.xamlPages) {
gp = new GeneralPage(aPageName, opts1.projectNamespace);
XamlFileGenerator.generateFile(gp, opts1);
generatePageAndModel(pige, gp);
}
}
}
开发者ID:surak8,项目名称:ProjectGen,代码行数:33,代码来源:XamlGenerator.cs
示例9: TaskFinished
public void TaskFinished(object sender, BuildEventArgs e)
{
var task = (CscTask)e.Task;
var generator = (GenerateMsBuildTask)sender;
var projectFileName = String.Format(
"{0}{1}{2}.csproj",
task.Sources.BaseDirectory.FullName,
Path.DirectorySeparatorChar,
Path.GetFileNameWithoutExtension(task.OutputFile.Name));
ProjectRootElement project = null;
if (!File.Exists(projectFileName))
project = ProjectRootElement.Create(projectFileName);
else
project = ProjectRootElement.Open(projectFileName);
var projectManipulator = new MB.Project(project);
project.DefaultTargets = "Build";
SetKnownProperties(project, task);
GenerateReferences(project, projectManipulator, task, generator);
GenerateCompileIncludes(project, projectManipulator, task);
project.EnsureImportExists("$(MSBuildToolsPath)\\Microsoft.CSharp.targets");
generator.RegisterProjectInSolution(project);
project.Save();
}
开发者ID:skolima,项目名称:generate-msbuild,代码行数:26,代码来源:CscTranslator.cs
示例10: ResolveProjectReferences
protected override IEnumerable<ProjectReference> ResolveProjectReferences(Project project)
{
return
base.ResolveProjectReferences(project)
//Don't include project reference to pMixins
.Where(p => !p.ToString().EndsWith(projectMatchingString));
}
开发者ID:prescottadam,项目名称:pMixins,代码行数:7,代码来源:TestMicrosoftBuildProjectAssemblyReferenceResolver.cs
示例11: SetUnevaluatedValueOverwritesElementValue
public void SetUnevaluatedValueOverwritesElementValue ()
{
string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<PropertyGroup>
<Foo>Bar</Foo>
<Item/>
<X>1</X>
<X>2</X>
<PATH>overriden</PATH>
</PropertyGroup>
</Project>";
var xml = XmlReader.Create (new StringReader (project_xml));
var root = ProjectRootElement.Create (xml);
var pe = root.Properties.First ();
Assert.AreEqual ("Bar", pe.Value, "#1");
var proj = new Project (root);
var prop = proj.Properties.First (p => p.Name == "Foo");
Assert.AreEqual ("Bar", prop.UnevaluatedValue, "#2");
prop.UnevaluatedValue = "x";
Assert.AreEqual ("x", pe.Value, "#3");
prop = proj.Properties.First (p => p.Name == "X");
Assert.AreEqual ("2", prop.UnevaluatedValue, "#4");
Assert.IsNotNull (prop.Predecessor, "#5");
Assert.AreEqual ("1", prop.Predecessor.UnevaluatedValue, "#6");
// environment property could also be Predecessor (and removed...maybe.
// I could reproduce only NRE = .NET bug with environment property so far.)
prop = proj.Properties.First (p => p.Name == "PATH");
Assert.AreEqual ("overriden", prop.UnevaluatedValue, "#7");
Assert.IsNotNull (prop.Predecessor, "#8");
}
开发者ID:nlhepler,项目名称:mono,代码行数:32,代码来源:ProjectPropertyTest.cs
示例12: LoadedProject
public static Microsoft.Build.Evaluation.Project LoadedProject(String path, bool cached)
{
Microsoft.Build.Evaluation.Project project = null;
ICollection<Microsoft.Build.Evaluation.Project> projects =
ProjectCollection.GlobalProjectCollection.GetLoadedProjects(path);
if (projects.Count == 0)
{
project = new Microsoft.Build.Evaluation.Project(path);
}
else
{
project = projects.First();
if(!cached)
{
//
// That is required to get C++ project properties re-evaluated
// with Visual Studio 2013 and Visual Studio 2015
//
ProjectCollection.GlobalProjectCollection.UnloadProject(project);
ProjectCollection.GlobalProjectCollection.UnloadAllProjects();
project = ProjectCollection.GlobalProjectCollection.LoadProject(path);
}
}
return project;
}
开发者ID:alux-xu,项目名称:ice-builder-visualstudio,代码行数:27,代码来源:MSBuildUtils.cs
示例13: ProjectProcessor
public ProjectProcessor(string path)
{
using (ProjectCollection pc = new ProjectCollection())
{
this.Project = pc.GetLoadedProjects(path).FirstOrDefault();
}
}
开发者ID:tomgrv,项目名称:PA.InnoSetupProcessor,代码行数:7,代码来源:ProjectProcessor.cs
示例14: CreateProjectInstancePassesEnvironment
public void CreateProjectInstancePassesEnvironment()
{
Project p = new Project();
ProjectInstance i = p.CreateProjectInstance();
Assert.Equal(true, i.GetPropertyValue("username") != null);
}
开发者ID:cameron314,项目名称:msbuild,代码行数:7,代码来源:ProjectInstance_Tests.cs
示例15: GetDependsOnTargetsAsList
public static IList<string> GetDependsOnTargetsAsList(this ProjectTargetInstance target,Project project)
{
if (target == null) { throw new ArgumentNullException("target"); }
if (project == null) { throw new ArgumentNullException("project"); }
List<string> targets = new List<string>();
string depTargets = target.DependsOnTargets != null ? target.DependsOnTargets : string.Empty;
string depTargetsEvaluated = project.ExpandString(depTargets);
string[] dtArray = depTargetsEvaluated.Split(';');
dtArray.ToList().ForEach(t => {
if (!string.IsNullOrWhiteSpace(t)) {
string tName = t.Trim();
if (!string.IsNullOrWhiteSpace(tName) &&
string.Compare(";", tName, StringComparison.InvariantCultureIgnoreCase) != 0) {
targets.Add(tName);
}
}
});
int numTarges = targets != null ? targets.Count() : 0;
string tempDebug = null;
if (numTarges >= 1) {
tempDebug = targets[0];
}
return targets;
}
开发者ID:sayedihashimi,项目名称:msbuild-analyzer,代码行数:28,代码来源:ProjectTargetInstanceExtension.cs
示例16: AddConfigurations
public static Project AddConfigurations(Project proj, string defaultConfig)
{
try {
var prop = proj.SetProperty("Configuration", defaultConfig);
prop.Xml.Condition = " '$(Configuration)' == '' ";
var debugPropGroup = proj.Xml.AddPropertyGroup();
var releasePropGroup = proj.Xml.AddPropertyGroup();
debugPropGroup.Condition = " '$(Configuration)' == 'Release' ";
debugPropGroup.SetProperty("OutputPath", "bin\\Release");
debugPropGroup.SetProperty("DebugSymbols", "Fasle");
debugPropGroup.SetProperty("DebugType", "None");
debugPropGroup.SetProperty("Optomize", "True");
debugPropGroup.SetProperty("CheckForOverflowUnderflow", "False");
debugPropGroup.SetProperty("DefineConstants", "TRACE");
releasePropGroup.Condition = " '$(Configuration)' == 'Debug' ";
releasePropGroup.SetProperty("OutputPath", "bin\\Debug");
releasePropGroup.SetProperty("DebugSymbols", "True");
releasePropGroup.SetProperty("DebugType", "Full");
releasePropGroup.SetProperty("Optomize", "False");
releasePropGroup.SetProperty("CheckForOverflowUnderflow", "True");
releasePropGroup.SetProperty("DefineConstants", "DEBUG;TRACE");
return proj;
} catch {
throw;
}
}
开发者ID:dbug13,项目名称:dotproject,代码行数:30,代码来源:ProjectBuilder.cs
示例17: CreateCompilation
private Compilation CreateCompilation(Project project)
{
var outputPath = project.GetProperty("OutputPath").EvaluatedValue;
if (!Path.IsPathRooted(outputPath))
{
outputPath = Path.Combine(Environment.CurrentDirectory, outputPath);
}
var searchPaths = ReadOnlyArray.OneOrZero(outputPath);
var resolver = new DiskFileResolver(searchPaths, searchPaths, Environment.CurrentDirectory, arch => true, System.Globalization.CultureInfo.CurrentCulture);
var metadataFileProvider = new MetadataFileProvider();
// just grab a list of references (if they're null, ignore)
var list = project.GetItems("Reference").Select(item =>
{
var include = item.EvaluatedInclude;
var path = resolver.ResolveAssemblyName(include);
if (path == null) return null;
return metadataFileProvider.GetReference(path);
}).Where(x => x != null);
return Compilation.Create(project.GetPropertyValue("AssemblyName"),
syntaxTrees: project.GetItems("Compile").Select(c => SyntaxTree.ParseFile(c.EvaluatedInclude)),
references: list);
}
开发者ID:pmacn,项目名称:DocPlagiarizer,代码行数:27,代码来源:DocPlagiarizerTask.cs
示例18: Hello
public void Hello ()
{
string project_xml = @"<Project ToolsVersion='4.0' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<UsingTask
TaskName='DoNothing'
TaskFactory='CodeTaskFactory'
AssemblyFile='$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll' >
<ParameterGroup />
<Task>
<Code Type='Fragment' Language='cs'>
<![CDATA[
// Display ""Hello, world!""
Log.LogWarning(""Hello, world!"");
]]> </Code>
</Task>
</UsingTask>
<Target Name='default'>
<DoNothing />
</Target>
</Project>";
var root = ProjectRootElement.Create (XmlReader.Create (new StringReader (project_xml)));
root.FullPath = "CodeTaskFactoryTest.Hello.proj";
var project = new Project (root);
Assert.IsTrue (project.Build (new ConsoleLogger (LoggerVerbosity.Diagnostic)), "Build");
}
开发者ID:Profit0004,项目名称:mono,代码行数:25,代码来源:CodeTaskFactoryTest.cs
示例19: SimpleImportAndSemanticValues
public void SimpleImportAndSemanticValues ()
{
string xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<Import Project='test_imported.proj' />
</Project>";
string imported = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<PropertyGroup>
<A>x</A>
<B>y</B>
</PropertyGroup>
<ItemGroup>
<X Include=""included.txt"" />
</ItemGroup>
</Project>";
using (var ts = File.CreateText (temp_file_name))
ts.Write (imported);
try {
var reader = XmlReader.Create (new StringReader (xml));
var root = ProjectRootElement.Create (reader);
Assert.AreEqual (temp_file_name, root.Imports.First ().Project, "#1");
var proj = new Project (root);
var prop = proj.GetProperty ("A");
Assert.IsNotNull (prop, "#2");
Assert.IsTrue (prop.IsImported, "#3");
var item = proj.GetItems ("X").FirstOrDefault ();
Assert.IsNotNull (item, "#4");
Assert.AreEqual ("included.txt", item.EvaluatedInclude, "#5");
} finally {
File.Delete (temp_file_name);
}
}
开发者ID:nlhepler,项目名称:mono,代码行数:31,代码来源:ResolvedImportTest.cs
示例20: BuildProject
public static MSbuildResult BuildProject(MsBuildSettings settings, string projectFileName, DirectoryInfo dir)
{
var result = new MSbuildResult();
var path = Path.Combine(dir.FullName, projectFileName);
var project = new Project(path, null, null, new ProjectCollection());
project.SetProperty("CscToolPath", settings.CompilerDirectory.FullName);
var includes = new HashSet<string>(
project.AllEvaluatedItems
.Where(i => i.ItemType == "None" || i.ItemType == "Content")
.Select(i => Path.GetFileName(i.EvaluatedInclude.ToLowerInvariant())));
foreach (var dll in settings.WellKnownLibsDirectory.GetFiles("*.dll"))
if (!includes.Contains(dll.Name.ToLowerInvariant()))
project.AddItem("None", dll.FullName);
project.Save();
using (var stringWriter = new StringWriter())
{
var logger = new ConsoleLogger(LoggerVerbosity.Minimal, stringWriter.Write, color => { }, () => { });
result.Success = SyncBuild(project, logger);
if (result.Success)
result.PathToExe = Path.Combine(project.DirectoryPath,
project.GetPropertyValue("OutputPath"),
project.GetPropertyValue("AssemblyName") + ".exe");
else
result.ErrorMessage = stringWriter.ToString();
return result;
}
}
开发者ID:kontur-edu,项目名称:uLearn,代码行数:27,代码来源:MsBuildRunner.cs
注:本文中的Microsoft.Build.Evaluation.Project类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论