本文整理汇总了C#中Microsoft.Build.Evaluation.Project.SaveLogicalProject方法的典型用法代码示例。如果您正苦于以下问题:C# Project.SaveLogicalProject方法的具体用法?C# Project.SaveLogicalProject怎么用?C# Project.SaveLogicalProject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Build.Evaluation.Project
的用法示例。
在下文中一共展示了Project.SaveLogicalProject方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Single
public void Single()
{
Project project = new Project();
project.SetProperty("p", "v1");
StringWriter writer = new StringWriter();
project.SaveLogicalProject(writer);
string expected = ObjectModelHelpers.CleanupFileContents(
@"<?xml version=""1.0"" encoding=""utf-16""?>
<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace"">
<PropertyGroup>
<p>v1</p>
</PropertyGroup>
</Project>");
Helpers.VerifyAssertLineByLine(expected, writer.ToString());
}
示例2: ProjectMetadata
public void ProjectMetadata()
{
string content = ObjectModelHelpers.CleanupFileContents(@"
<Project DefaultTargets='Build' ToolsVersion='msbuilddefaulttoolsversion' xmlns='msbuildnamespace'>
<ItemGroup>
<ProjectReference Include='..\CLREXE\CLREXE.vcxproj'>
<Project>{3699f81b-2d03-46c5-abd7-e88a4c946f28}</Project>
</ProjectReference>
</ItemGroup>
</Project>");
ProjectRootElement xml = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));
Project project = new Project(xml);
StringWriter writer = new StringWriter();
project.SaveLogicalProject(writer);
string expected = ObjectModelHelpers.CleanupFileContents(
@"<?xml version=""1.0"" encoding=""utf-16""?>
<Project DefaultTargets=""Build"" ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace"">
<ItemGroup>
<ProjectReference Include=""..\CLREXE\CLREXE.vcxproj"">
<Project>{3699f81b-2d03-46c5-abd7-e88a4c946f28}</Project>
</ProjectReference>
</ItemGroup>
</Project>");
Helpers.VerifyAssertLineByLine(expected, writer.ToString());
}
示例3: InitialTargetsOuterAndInner
public void InitialTargetsOuterAndInner()
{
ProjectRootElement xml1 = ProjectRootElement.Create("p1");
xml1.InitialTargets = "i1";
xml1.AddImport("p2");
ProjectRootElement xml2 = ProjectRootElement.Create("p2");
xml2.InitialTargets = "i2";
Project project = new Project(xml1);
StringWriter writer = new StringWriter();
project.SaveLogicalProject(writer);
string expected = ObjectModelHelpers.CleanupFileContents(
@"<?xml version=""1.0"" encoding=""utf-16""?>
<!--
============================================================================================================================================
" + CurrentDirectoryXmlCommentFriendly + Path.DirectorySeparatorChar + @"p1
============================================================================================================================================
-->
<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace"" InitialTargets=""i1;i2"">
<!--
============================================================================================================================================
<Import Project=""p2"">
" + CurrentDirectoryXmlCommentFriendly + Path.DirectorySeparatorChar + @"p2
============================================================================================================================================
-->
<!--
============================================================================================================================================
</Import>
" + CurrentDirectoryXmlCommentFriendly + Path.DirectorySeparatorChar + @"p1
============================================================================================================================================
-->
</Project>");
Helpers.VerifyAssertLineByLine(expected, writer.ToString());
}
示例4: ImportWildcard
public void ImportWildcard()
{
string directory = null;
ProjectRootElement xml0, xml1 = null, xml2 = null, xml3 = null;
try
{
directory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(directory);
xml0 = ProjectRootElement.Create("p1");
xml0.AddImport(directory + "\\*.targets");
xml1 = ProjectRootElement.Create(directory + "\\1.targets");
xml1.AddProperty("p", "v1");
xml1.Save();
xml2 = ProjectRootElement.Create(directory + "\\2.targets");
xml2.AddProperty("p", "v2");
xml2.Save();
xml3 = ProjectRootElement.Create(directory + "\\3.xxxxxx");
xml3.AddProperty("p", "v3");
xml3.Save();
Project project = new Project(xml0);
StringWriter writer = new StringWriter();
project.SaveLogicalProject(writer);
string expected = ObjectModelHelpers.CleanupFileContents(
@"<?xml version=""1.0"" encoding=""utf-16""?>
<!--
============================================================================================================================================
" + CurrentDirectoryXmlCommentFriendly + Path.DirectorySeparatorChar + @"p1
============================================================================================================================================
-->
<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace"">
<!--
============================================================================================================================================
<Import Project=""" + Path.Combine(directory, "*.targets") + @""">
" + Path.Combine(directory, "1.targets") + @"
============================================================================================================================================
-->
<PropertyGroup>
<p>v1</p>
</PropertyGroup>
<!--
============================================================================================================================================
</Import>
============================================================================================================================================
-->
<!--
============================================================================================================================================
<Import Project=""" + Path.Combine(directory, "*.targets") + @""">
" + Path.Combine(directory, "2.targets") + @"
============================================================================================================================================
-->
<PropertyGroup>
<p>v2</p>
</PropertyGroup>
<!--
============================================================================================================================================
</Import>
" + CurrentDirectoryXmlCommentFriendly + Path.DirectorySeparatorChar + @"p1
============================================================================================================================================
-->
</Project>");
Helpers.VerifyAssertLineByLine(expected, writer.ToString());
}
finally
{
File.Delete(xml1.FullPath);
File.Delete(xml2.FullPath);
File.Delete(xml3.FullPath);
Directory.Delete(directory);
}
}
示例5: ImportGroupFalseCondition
public void ImportGroupFalseCondition()
{
ProjectRootElement xml1 = ProjectRootElement.Create("p1");
xml1.AddProperty("p", "v1");
xml1.AddImportGroup().AddImport("p2");
xml1.LastChild.Condition = "false";
ProjectRootElement xml2 = ProjectRootElement.Create("p2");
xml2.AddProperty("p", "v2");
Project project = new Project(xml1);
StringWriter writer = new StringWriter();
project.SaveLogicalProject(writer);
string expected = ObjectModelHelpers.CleanupFileContents(
@"<?xml version=""1.0"" encoding=""utf-16""?>
<!--
============================================================================================================================================
" + CurrentDirectoryXmlCommentFriendly + Path.DirectorySeparatorChar + @"p1
============================================================================================================================================
-->
<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace"">
<PropertyGroup>
<p>v1</p>
</PropertyGroup>
<!--<ImportGroup Condition=""false"">-->
<!--<Import Project=""p2"" />-->
<!--</ImportGroup>-->
</Project>");
Helpers.VerifyAssertLineByLine(expected, writer.ToString());
}
示例6: TwoWithContent
public void TwoWithContent()
{
string one = ObjectModelHelpers.CleanupFileContents(
@"<?xml version=""1.0"" encoding=""utf-16""?>
<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace"">
<PropertyGroup>
<p>v0</p>
</PropertyGroup>
<Import Project=""p2""/>
<PropertyGroup>
<p>v2</p>
</PropertyGroup>
</Project>");
string two = ObjectModelHelpers.CleanupFileContents(
@"<?xml version=""1.0"" encoding=""utf-16""?>
<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace"">
<PropertyGroup>
<p>v1</p>
</PropertyGroup>
</Project>");
ProjectRootElement twoXml = ProjectRootElement.Create(XmlReader.Create(new StringReader(two)));
twoXml.FullPath = "p2";
Project project = new Project(XmlTextReader.Create(new StringReader(one)));
StringWriter writer = new StringWriter();
project.SaveLogicalProject(writer);
string expected = ObjectModelHelpers.CleanupFileContents(
@"<?xml version=""1.0"" encoding=""utf-16""?>
<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace"">
<PropertyGroup>
<p>v0</p>
</PropertyGroup>
<!--
============================================================================================================================================
<Import Project=""p2"">
" + CurrentDirectoryXmlCommentFriendly + Path.DirectorySeparatorChar + @"p2
============================================================================================================================================
-->
<PropertyGroup>
<p>v1</p>
</PropertyGroup>
<!--
============================================================================================================================================
</Import>
============================================================================================================================================
-->
<PropertyGroup>
<p>v2</p>
</PropertyGroup>
</Project>");
Helpers.VerifyAssertLineByLine(expected, writer.ToString());
}
示例7: DefaultTargetsInnerOnly
public void DefaultTargetsInnerOnly()
{
ProjectRootElement xml1 = ProjectRootElement.Create("p1");
xml1.AddImport("p2");
xml1.AddImport("p3");
ProjectRootElement xml2 = ProjectRootElement.Create("p2");
xml2.DefaultTargets = "d2";
ProjectRootElement xml3 = ProjectRootElement.Create("p3");
xml3.DefaultTargets = "d3";
Project project = new Project(xml1);
StringWriter writer = new StringWriter();
project.SaveLogicalProject(writer);
string expected = ObjectModelHelpers.CleanupFileContents(
@"<?xml version=""1.0"" encoding=""utf-16""?>
<!--
============================================================================================================================================
" + Directory.GetCurrentDirectory() + @"\p1
============================================================================================================================================
-->
<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace"" DefaultTargets=""d2"">
<!--
============================================================================================================================================
<Import Project=""p2"">
" + Directory.GetCurrentDirectory() + @"\p2
============================================================================================================================================
-->
<!--
============================================================================================================================================
</Import>
" + Directory.GetCurrentDirectory() + @"\p1
============================================================================================================================================
-->
<!--
============================================================================================================================================
<Import Project=""p3"">
" + Directory.GetCurrentDirectory() + @"\p3
============================================================================================================================================
-->
<!--
============================================================================================================================================
</Import>
" + Directory.GetCurrentDirectory() + @"\p1
============================================================================================================================================
-->
</Project>");
Helpers.VerifyAssertLineByLine(expected, writer.ToString());
}
示例8: ImportGroupDoubleChildPlusCondition
public void ImportGroupDoubleChildPlusCondition()
{
ProjectRootElement xml1 = ProjectRootElement.Create("p1");
xml1.AddProperty("p", "v1");
ProjectImportGroupElement group = xml1.AddImportGroup();
group.Condition = "true";
group.AddImport("p2");
group.AddImport("p3");
ProjectRootElement xml2 = ProjectRootElement.Create("p2");
xml2.AddProperty("p", "v2");
ProjectRootElement xml3 = ProjectRootElement.Create("p3");
xml3.AddProperty("p", "v3");
Project project = new Project(xml1);
StringWriter writer = new StringWriter();
project.SaveLogicalProject(writer);
string expected = ObjectModelHelpers.CleanupFileContents(
@"<?xml version=""1.0"" encoding=""utf-16""?>
<!--
============================================================================================================================================
" + Directory.GetCurrentDirectory() + @"\p1
============================================================================================================================================
-->
<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace"">
<PropertyGroup>
<p>v1</p>
</PropertyGroup>
<!--<ImportGroup Condition=""true"">-->
<!--
============================================================================================================================================
<Import Project=""p2"">
" + Directory.GetCurrentDirectory() + @"\p2
============================================================================================================================================
-->
<PropertyGroup>
<p>v2</p>
</PropertyGroup>
<!--
============================================================================================================================================
</Import>
" + Directory.GetCurrentDirectory() + @"\p1
============================================================================================================================================
-->
<!--
============================================================================================================================================
<Import Project=""p3"">
" + Directory.GetCurrentDirectory() + @"\p3
============================================================================================================================================
-->
<PropertyGroup>
<p>v3</p>
</PropertyGroup>
<!--
============================================================================================================================================
</Import>
" + Directory.GetCurrentDirectory() + @"\p1
============================================================================================================================================
-->
<!--</ImportGroup>-->
</Project>");
Helpers.VerifyAssertLineByLine(expected, writer.ToString());
}
示例9: PreprocessorFormatting
public void PreprocessorFormatting()
{
string content = ObjectModelHelpers.CleanupFileContents(@"
<Project DefaultTargets='Build' ToolsVersion='msbuilddefaulttoolsversion' xmlns='msbuildnamespace'>
<Target
Name=""XamlPreCompile""
Inputs=""$(MSBuildAllProjects);
@(Compile);
@(_CoreCompileResourceInputs);""
/>
</Project>");
ProjectRootElement xml = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)), ProjectCollection.GlobalProjectCollection,
preserveFormatting: true);
Project project = new Project(xml);
StringWriter writer = new StringWriter();
project.SaveLogicalProject(writer);
string actual = writer.ToString();
string expected = @"<?xml version=""1.0"" encoding=""utf-16""?>" +
content;
VerifyAssertLineByLine(expected, actual);
}