本文整理汇总了C#中Microsoft.Build.UnitTests.MockLogger类的典型用法代码示例。如果您正苦于以下问题:C# MockLogger类的具体用法?C# MockLogger怎么用?C# MockLogger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MockLogger类属于Microsoft.Build.UnitTests命名空间,在下文中一共展示了MockLogger类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialize
public void Initialize()
{
engine = new Engine();
myProject = new Project(engine);
myLogger = new MockLogger();
myProject.ParentEngine.RegisterLogger(myLogger);
}
示例2: ImportFromExtensionsPathNotFound
public void ImportFromExtensionsPathNotFound()
{
string extnDir1 = null;
string mainProjectPath = null;
try {
extnDir1 = GetNewExtensionsPathAndCreateFile("extensions1", Path.Combine("foo", "extn.proj"), GetExtensionTargetsFileContent1());
mainProjectPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("main.proj", GetMainTargetFileContent());
var projColln = new ProjectCollection();
projColln.ResetToolsetsForTests(WriteConfigFileAndGetReader("MSBuildExtensionsPath", extnDir1, Path.Combine("tmp", "nonexistant")));
var logger = new MockLogger();
projColln.RegisterLogger(logger);
Assert.Throws<InvalidProjectFileException>(() => projColln.LoadProject(mainProjectPath));
logger.AssertLogContains("MSB4226");
} finally {
if (mainProjectPath != null)
{
FileUtilities.DeleteNoThrow(mainProjectPath);
}
if (extnDir1 != null)
{
FileUtilities.DeleteDirectoryNoThrow(extnDir1, recursive: true);
}
}
}
示例3: MockEngine
public MockEngine(bool logToConsole)
{
mockLogger = new MockLogger();
this.logToConsole = logToConsole;
this.engine = new Engine(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath));
this.engine.RegisterLogger(new ConsoleLogger());
this.engine.RegisterLogger(mockLogger);
engineGlobalProperties = new BuildPropertyGroup();
}
示例4: Initialize
public void Initialize()
{
ObjectModelHelpers.DeleteTempProjectDirectory();
engine = new Engine();
engine.DefaultToolsVersion = "4.0";
project = new Project(engine);
logger = new MockLogger();
project.ParentEngine.RegisterLogger(logger);
}
示例5: InvalidToolPath
public void InvalidToolPath()
{
//Note Engine's BinPath is distinct from the ToolsVersion's ToolsPath
Engine e = new Engine();
MockLogger mockLogger = new MockLogger();
e.RegisterLogger(mockLogger);
ToolsetState t = new ToolsetState(e, new Toolset("toolsversionname", "invalid||path"), new GetFiles(this.getFiles), new LoadXmlFromPath(this.loadXmlFromPath));
TaskRegistry taskRegistry = (TaskRegistry) t.GetTaskRegistry(null);
Console.WriteLine(mockLogger.FullLog);
Assert.AreEqual(1, mockLogger.WarningCount, "Expected a warning for invalid character in toolpath");
}
示例6: AddNewErrorWarningMessageElement
public void AddNewErrorWarningMessageElement()
{
MockLogger logger = new MockLogger();
Project project = ObjectModelHelpers.CreateInMemoryProject(
"<Project DefaultTargets=`Build` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>" +
"<Target Name=`Build`>" +
"</Target>" +
"</Project>",
logger);
Target target = project.Targets["Build"];
SolutionWrapperProject.AddErrorWarningMessageElement(target, XMakeElements.message, true, "SolutionVenusProjectNoClean");
SolutionWrapperProject.AddErrorWarningMessageElement(target, XMakeElements.warning, true, "SolutionParseUnknownProjectType", "proj1.csproj");
SolutionWrapperProject.AddErrorWarningMessageElement(target, XMakeElements.error, true, "SolutionVCProjectNoPublish");
project.Build(null, null);
string code = null;
string keyword = null;
string text = ResourceUtilities.FormatResourceString(out code, out keyword, "SolutionParseUnknownProjectType", "proj1.csproj");
// check the error event
Assertion.AssertEquals(1, logger.Warnings.Count);
BuildWarningEventArgs warning = logger.Warnings[0];
Assertion.AssertEquals(text, warning.Message);
Assertion.AssertEquals(code, warning.Code);
Assertion.AssertEquals(keyword, warning.HelpKeyword);
code = null;
keyword = null;
text = ResourceUtilities.FormatResourceString(out code, out keyword, "SolutionVCProjectNoPublish");
// check the warning event
Assertion.AssertEquals(1, logger.Errors.Count);
BuildErrorEventArgs error = logger.Errors[0];
Assertion.AssertEquals(text, error.Message);
Assertion.AssertEquals(code, error.Code);
Assertion.AssertEquals(keyword, error.HelpKeyword);
code = null;
keyword = null;
text = ResourceUtilities.FormatResourceString(out code, out keyword, "SolutionVenusProjectNoClean");
// check the message event
Assertion.Assert("Log should contain the regular message", logger.FullLog.Contains(text));
}
示例7: TargetARM
public void TargetARM()
{
string file = null;
string outputPath = Path.GetTempPath() + "\\" + Guid.NewGuid().ToString("N");
try
{
file = Helpers.CreateFiles("class1.cs")[0];
MockLogger logger = new MockLogger();
Project project = ObjectModelHelpers.CreateInMemoryProject(
@"
<Project DefaultTargets=`Build` ToolsVersion=`4.0` xmlns=`msbuildnamespace`>
<PropertyGroup>
<OutputPath>" + outputPath + @"</OutputPath>
<AssemblyName>MyAssembly</AssemblyName>
<OutputType>Library</OutputType>
<Configuration>Debug</Configuration>
<PlatformTarget>arm</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Compile Include=`" + file + @"` />
</ItemGroup>
<Import Project=`$(MSBuildToolsPath)\Microsoft.CSharp.Targets` />
</Project>
",
logger
);
project.Build();
logger.AssertLogContains(" /platform:arm ");
}
finally
{
if (file != null)
{
File.Delete(file);
}
ObjectModelHelpers.DeleteDirectory(outputPath);
}
}
示例8: WarningLoggedIfNoDefaultTasksFound
public void WarningLoggedIfNoDefaultTasksFound()
{
//Note Engine's BinPath is distinct from the ToolsVersion's ToolsPath
Engine e = new Engine();
MockLogger mockLogger = new MockLogger();
e.RegisterLogger(mockLogger);
ToolsetState t = new ToolsetState(e, new Toolset("toolsversionname", "c:\\directory1\\directory2\\doesntexist"), new GetFiles(this.getFiles), new LoadXmlFromPath(this.loadXmlFromPath));
TaskRegistry taskRegistry = (TaskRegistry) t.GetTaskRegistry(null);
string[] unexpectedRegisteredTasks = { "a1", "a2", "a3", "a4", "b1", "c1", "d1", "e1", "f1", "g1", "g2", "g3", "11", "12", "13", "21" };
Assert.AreEqual(1, mockLogger.WarningCount, "Expected 1 warning logged!");
foreach (string unexpectedRegisteredTask in unexpectedRegisteredTasks)
{
Hashtable registeredTasks;
Assert.IsFalse(taskRegistry.FindRegisteredTasks(unexpectedRegisteredTask, true, out registeredTasks),
String.Format("Unexpected task '{0}' registered!", unexpectedRegisteredTask));
}
}
示例9: Basic
public void Basic()
{
MockLogger l = new MockLogger();
Project p = ObjectModelHelpers.CreateInMemoryProject(@"
<Project DefaultTargets=`Build` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
<Target Name='CleanUp'>
<Message Text='CleanUp-was-called.'/>
</Target>
<Target Name='Build'>
<Error Text='This is an error.'/>
<OnError ExecuteTargets='CleanUp'/>
</Target>
</Project>",
l
);
p.Build(new string [] {"Build"}, null);
Assertion.Assert("Expected one error because 'Build' failed.", l.ErrorCount==1);
Assertion.Assert("The CleanUp target should have been called.", (l.FullLog.IndexOf("CleanUp-was-called") != -1));
}
示例10: VerifyToolsetAndToolLocationHelperAgree
public void VerifyToolsetAndToolLocationHelperAgree()
{
string projectContents = ObjectModelHelpers.CleanupFileContents(@"
<Project xmlns='msbuildnamespace' ToolsVersion='msbuilddefaulttoolsversion'>
<UsingTask TaskName='VerifySdkPaths' TaskFactory='CodeTaskFactory' AssemblyFile='$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll' >
<ParameterGroup>
<Sdk35ToolsPath />
<Sdk40ToolsPath />
<WindowsSDK80Path />
</ParameterGroup>
<Task>
<Using Namespace='Microsoft.Win32'/>
<Code>
<![CDATA[
string pathTo35Sdk = ToolLocationHelper.GetPathToDotNetFrameworkSdkFile(""gacutil.exe"", TargetDotNetFrameworkVersion.Version35);
if (!String.IsNullOrEmpty(pathTo35Sdk))
{
pathTo35Sdk = Path.GetDirectoryName(pathTo35Sdk) + ""\\"";
}
string pathTo40Sdk = ToolLocationHelper.GetPathToDotNetFrameworkSdkFile(""gacutil.exe"", TargetDotNetFrameworkVersion.VersionLatest);
if (!String.IsNullOrEmpty(pathTo40Sdk))
{
pathTo40Sdk = Path.GetDirectoryName(pathTo40Sdk) + ""\\"";
}
string pathTo81WinSDK = ToolLocationHelper.GetPathToWindowsSdk(TargetDotNetFrameworkVersion.VersionLatest, VisualStudioVersion.VersionLatest);" +
s_verifyToolsetAndToolLocationHelperProjectCommonContent +
@"if (!String.Equals(WindowsSDK80Path, pathTo81WinSDK, StringComparison.OrdinalIgnoreCase))
{
Log.LogError(""WindowsSDK80Path is incorrect! Registry: {0} ToolLocationHelper: {1}"", WindowsSDK80Path, pathTo81WinSDK);
}
return !Log.HasLoggedErrors;
]]>
</Code>
</Task>
</UsingTask>
<Target Name='Build'>
<VerifySdkPaths Sdk35ToolsPath='$(Sdk35ToolsPath)' Sdk40ToolsPath='$(Sdk40ToolsPath)' WindowsSDK80Path='$(WindowsSDK80Path)' />
</Target>
</Project>");
ILogger logger = new MockLogger(_output);
ProjectCollection collection = new ProjectCollection();
Project p = ObjectModelHelpers.CreateInMemoryProject(collection, projectContents, logger);
bool success = p.Build(logger);
Assert.True(success); // "Build Failed. See Std Out for details."
}
示例11: SemicolonInConfiguration_UsingTaskHost
public void SemicolonInConfiguration_UsingTaskHost()
{
string originalOverrideTaskHostVariable = Environment.GetEnvironmentVariable("MSBUILDFORCEALLTASKSOUTOFPROC");
try
{
Environment.SetEnvironmentVariable("MSBUILDFORCEALLTASKSOUTOFPROC", "1");
ObjectModelHelpers.DeleteTempProjectDirectory();
// ---------------------
// Foo.csproj
// ---------------------
ObjectModelHelpers.CreateFileInTempProjectDirectory("foo.csproj", @"
<Project DefaultTargets=`Build` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`http://schemas.microsoft.com/developer/msbuild/2003`>
<Import Project=`$(MSBuildBinPath)\Microsoft.Common.props` />
<PropertyGroup>
<Configuration Condition=` '$(Configuration)' == '' `>Debug</Configuration>
<Platform Condition=` '$(Platform)' == '' `>AnyCPU</Platform>
<OutputType>Library</OutputType>
<AssemblyName>ClassLibrary16</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=` '$(Configuration)|$(Platform)' == 'a%3bb%27c|AnyCPU' `>
<OutputPath>bin\a%3bb%27c\</OutputPath>
</PropertyGroup>
<ItemGroup>
<Reference Include=`System` />
<Compile Include=`Class1.cs` />
</ItemGroup>
<Import Project=`$(MSBuildBinPath)\Microsoft.CSharp.targets` />
</Project>
");
// ---------------------
// Class1.cs
// ---------------------
ObjectModelHelpers.CreateFileInTempProjectDirectory("Class1.cs", @"
namespace ClassLibrary16
{
public class Class1
{
}
}
");
// Create a logger.
MockLogger logger = new MockLogger();
Project project = ObjectModelHelpers.LoadProjectFileInTempProjectDirectory("foo.csproj");
// Build the default targets using the Configuration "a;b'c".
project.SetGlobalProperty("Configuration", EscapingUtilities.Escape("a;b'c"));
bool success = project.Build(logger);
Assert.True(success); // "Build failed. See Standard Out tab for details"
ObjectModelHelpers.AssertFileExistsInTempProjectDirectory(@"obj\a;b'c\ClassLibrary16.dll");
ObjectModelHelpers.AssertFileExistsInTempProjectDirectory(@"bin\a;b'c\ClassLibrary16.dll");
logger.AssertLogContains(String.Format("foo -> {0}", Path.Combine(ObjectModelHelpers.TempProjectDir, @"bin\a;b'c\ClassLibrary16.dll")));
}
finally
{
Environment.SetEnvironmentVariable("MSBUILDFORCEALLTASKSOUTOFPROC", originalOverrideTaskHostVariable);
}
}
示例12: ResetLogger
/// <summary>
/// Un-registers the existing logger and registers a new copy.
/// We will use this when we do multiple builds so that we can safely
/// assert on log messages for that particular build.
/// </summary>
private void ResetLogger()
{
engine.UnregisterAllLoggers();
logger = new MockLogger();
project.ParentEngine.RegisterLogger(logger);
}
示例13: EscapedWildcardsShouldNotBeExpanded_InTaskHost
public void EscapedWildcardsShouldNotBeExpanded_InTaskHost()
{
MockLogger logger = new MockLogger();
try
{
// Populate the project directory with three physical files on disk -- a.weirdo, b.weirdo, c.weirdo.
EscapingInProjectsHelper.CreateThreeWeirdoFiles();
Project project = ObjectModelHelpers.CreateInMemoryProject(@"
<Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`http://schemas.microsoft.com/developer/msbuild/2003`>
<UsingTask TaskName=`Message` AssemblyFile=`$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll` TaskFactory=`TaskHostFactory` />
<Target Name=`t`>
<ItemGroup>
<type Include=`%2A` Exclude=``/>
</ItemGroup>
<Message Text=`[@(type)]`/>
</Target>
</Project>
");
bool success = project.Build(logger);
Assert.True(success); // "Build failed. See Standard Out tab for details"
logger.AssertLogContains("[*]");
}
finally
{
EscapingInProjectsHelper.CleanupWeirdoFiles();
}
}
示例14: TargetNamesAlwaysUnescaped_Override
public void TargetNamesAlwaysUnescaped_Override()
{
Project project = ObjectModelHelpers.CreateInMemoryProject(@"
<Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`http://schemas.microsoft.com/developer/msbuild/2003`>
<Target Name=`%3B`>
<Message Text=`[WRONG]` />
</Target>
<Target Name=`;`>
<Message Text=`[OVERRIDE]` />
</Target>
</Project>
");
MockLogger logger = new MockLogger();
bool success = project.Build(logger);
Assert.True(success); // "Build failed. See Standard Out tab for details"
logger.AssertLogContains("[OVERRIDE]");
}
示例15: ProjectToolsVersionOverwriteIsTrue
public void ProjectToolsVersionOverwriteIsTrue()
{
try
{
string projectContent =
@"
<Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
<Target Name=`a`>
<Message Text=`[a=$(MSBuildToolsVersion)]`/>
<MSBuild Projects=`p2.proj`/>
<MSBuild Projects=`p2.proj` ToolsVersion='3.5'/>
<MSBuild Projects=`p2.proj` ToolsVersion='2.0'/>
</Target>
</Project>
";
string projectContent2 =
@"
<Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
<Target Name=`a`>
<Message Text=`[b=$(MSBuildToolsVersion)]`/>
</Target>
</Project>
";
MockLogger logger = new MockLogger();
Engine e = new Engine();
e.RegisterLogger(logger);
string p1Path = ObjectModelHelpers.CreateFileInTempProjectDirectory("p1.proj", projectContent);
string p2Path = ObjectModelHelpers.CreateFileInTempProjectDirectory("p2.proj", projectContent2);
Project p1 = new Project(e, "2.0");
p1.Load(p1Path);
p1.Build();
logger.AssertLogContains("[a=2.0]");
logger.AssertLogContains("[b=2.0]");
Assertion.Assert("Cachescope should have an entry with 2.0", e.CacheManager.GetCacheScope(p1Path, new BuildPropertyGroup(), "2.0", CacheContentType.BuildResults) != null);
Assertion.Assert("Cachescope should have an entry with 2.0", e.CacheManager.GetCacheScope(p2Path, new BuildPropertyGroup(), "2.0", CacheContentType.BuildResults) != null);
}
finally
{
ObjectModelHelpers.DeleteTempProjectDirectory();
}
}