本文整理汇总了C#中Microsoft.Build.Utilities.TaskLoggingHelper.LogWarningWithCodeFromResources方法的典型用法代码示例。如果您正苦于以下问题:C# TaskLoggingHelper.LogWarningWithCodeFromResources方法的具体用法?C# TaskLoggingHelper.LogWarningWithCodeFromResources怎么用?C# TaskLoggingHelper.LogWarningWithCodeFromResources使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Build.Utilities.TaskLoggingHelper
的用法示例。
在下文中一共展示了TaskLoggingHelper.LogWarningWithCodeFromResources方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeserializeCache
internal static StateFileBase DeserializeCache(string stateFile, TaskLoggingHelper log, Type requiredReturnType)
{
StateFileBase o = null;
try
{
if (((stateFile == null) || (stateFile.Length <= 0)) || !File.Exists(stateFile))
{
return o;
}
using (FileStream stream = new FileStream(stateFile, FileMode.Open))
{
object obj2 = new BinaryFormatter().Deserialize(stream);
o = obj2 as StateFileBase;
if ((o == null) && (obj2 != null))
{
log.LogMessageFromResources("General.CouldNotReadStateFileMessage", new object[] { stateFile, log.FormatResourceString("General.IncompatibleStateFileType", new object[0]) });
}
if ((o != null) && !requiredReturnType.IsInstanceOfType(o))
{
log.LogWarningWithCodeFromResources("General.CouldNotReadStateFile", new object[] { stateFile, log.FormatResourceString("General.IncompatibleStateFileType", new object[0]) });
o = null;
}
}
}
catch (Exception exception)
{
log.LogWarningWithCodeFromResources("General.CouldNotReadStateFile", new object[] { stateFile, exception.Message });
}
return o;
}
示例2: SerializeCache
/// <summary>
/// Writes the contents of this object out to the specified file.
/// </summary>
/// <param name="stateFile"></param>
virtual internal void SerializeCache(string stateFile, TaskLoggingHelper log)
{
try
{
if (!string.IsNullOrEmpty(stateFile))
{
if (File.Exists(stateFile))
{
File.Delete(stateFile);
}
using (FileStream s = new FileStream(stateFile, FileMode.CreateNew))
{
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(s, this);
}
}
}
catch (Exception e)
{
// If there was a problem writing the file (like it's read-only or locked on disk, for
// example), then eat the exception and log a warning. Otherwise, rethrow.
if (ExceptionHandling.NotExpectedSerializationException(e))
throw;
// Not being able to serialize the cache is not an error, but we let the user know anyway.
// Don't want to hold up processing just because we couldn't read the file.
log.LogWarningWithCodeFromResources("General.CouldNotWriteStateFile", stateFile, e.Message);
}
}
示例3: GetPathOfTypeLib
internal static bool GetPathOfTypeLib(TaskLoggingHelper log, ref System.Runtime.InteropServices.ComTypes.TYPELIBATTR typeLibAttr, out string typeLibPath)
{
typeLibPath = "";
try
{
typeLibPath = Microsoft.Build.Tasks.NativeMethods.QueryPathOfRegTypeLib(ref typeLibAttr.guid, typeLibAttr.wMajorVerNum, typeLibAttr.wMinorVerNum, typeLibAttr.lcid);
typeLibPath = Environment.ExpandEnvironmentVariables(typeLibPath);
}
catch (COMException exception)
{
log.LogWarningWithCodeFromResources("ResolveComReference.CannotGetPathForTypeLib", new object[] { typeLibAttr.guid, typeLibAttr.wMajorVerNum, typeLibAttr.wMinorVerNum, exception.Message });
return false;
}
if (((typeLibPath != null) && (typeLibPath.Length > 0)) && (typeLibPath[typeLibPath.Length - 1] == '\0'))
{
typeLibPath = typeLibPath.Substring(0, typeLibPath.Length - 1);
}
if ((typeLibPath != null) && (typeLibPath.Length > 0))
{
return true;
}
log.LogWarningWithCodeFromResources("ResolveComReference.CannotGetPathForTypeLib", new object[] { typeLibAttr.guid, typeLibAttr.wMajorVerNum, typeLibAttr.wMinorVerNum, "" });
return false;
}
示例4: DeleteFile
internal static void DeleteFile(string stateFile, TaskLoggingHelper log)
{
try
{
if (((stateFile != null) && (stateFile.Length > 0)) && File.Exists(stateFile))
{
File.Delete(stateFile);
}
}
catch (Exception exception)
{
if (Microsoft.Build.Shared.ExceptionHandling.NotExpectedException(exception))
{
throw;
}
log.LogWarningWithCodeFromResources("General.CouldNotDeleteStateFile", new object[] { stateFile, exception.Message });
}
}
示例5: DeleteFile
/// <summary>
/// Deletes the state file from disk
/// </summary>
/// <param name="stateFile"></param>
/// <param name="log"></param>
static internal void DeleteFile(string stateFile, TaskLoggingHelper log)
{
try
{
if (stateFile != null && stateFile.Length > 0)
{
if (File.Exists(stateFile))
{
File.Delete(stateFile);
}
}
}
catch (Exception e)
{
// If there was a problem deleting the file (like it's read-only or locked on disk, for
// example), then eat the exception and log a warning. Otherwise, rethrow.
if (ExceptionHandling.NotExpectedException(e))
throw;
log.LogWarningWithCodeFromResources("General.CouldNotDeleteStateFile", stateFile, e.Message);
}
}
示例6: LogWarningWithCodeFromResources
/// <summary>
/// Logs a warning using the specified resource string.
/// </summary>
/// <param name="messageResourceName">The name of the string resource to load.</param>
/// <param name="messageArgs">Optional arguments for formatting the loaded string.</param>
/// <exception cref="ArgumentNullException">Thrown when <c>messageResourceName</c> is null.</exception>
internal static void LogWarningWithCodeFromResources(TaskLoggingHelper Log, string messageResourceName, params object[] messageArgs)
{
// Only log when we have been passed a TaskLoggingHelper
if (Log != null)
{
Log.LogWarningWithCodeFromResources(messageResourceName, messageArgs);
}
}
示例7: CreateManifestNameImpl
internal static string CreateManifestNameImpl(string fileName, string linkFileName, bool prependCultureAsDirectory, string rootNamespace, string dependentUponFileName, Stream binaryStream, TaskLoggingHelper log)
{
string str = linkFileName;
if ((str == null) || (str.Length == 0))
{
str = fileName;
}
Culture.ItemCultureInfo itemCultureInfo = Culture.GetItemCultureInfo(str, dependentUponFileName);
StringBuilder builder = new StringBuilder();
if (binaryStream != null)
{
ExtractedClassName firstClassNameFullyQualified = VisualBasicParserUtilities.GetFirstClassNameFullyQualified(binaryStream);
if (firstClassNameFullyQualified.IsInsideConditionalBlock && (log != null))
{
log.LogWarningWithCodeFromResources("CreateManifestResourceName.DefinitionFoundWithinConditionalDirective", new object[] { dependentUponFileName, str });
}
if ((firstClassNameFullyQualified.Name != null) && (firstClassNameFullyQualified.Name.Length > 0))
{
if ((rootNamespace != null) && (rootNamespace.Length > 0))
{
builder.Append(rootNamespace).Append(".").Append(firstClassNameFullyQualified.Name);
}
else
{
builder.Append(firstClassNameFullyQualified.Name);
}
if ((itemCultureInfo.culture != null) && (itemCultureInfo.culture.Length > 0))
{
builder.Append(".").Append(itemCultureInfo.culture);
}
}
}
if (builder.Length == 0)
{
if ((rootNamespace != null) && (rootNamespace.Length > 0))
{
builder.Append(rootNamespace).Append(".");
}
string extension = Path.GetExtension(itemCultureInfo.cultureNeutralFilename);
if (((string.Compare(extension, ".resx", StringComparison.OrdinalIgnoreCase) == 0) || (string.Compare(extension, ".restext", StringComparison.OrdinalIgnoreCase) == 0)) || (string.Compare(extension, ".resources", StringComparison.OrdinalIgnoreCase) == 0))
{
builder.Append(Path.GetFileNameWithoutExtension(itemCultureInfo.cultureNeutralFilename));
if ((itemCultureInfo.culture != null) && (itemCultureInfo.culture.Length > 0))
{
builder.Append(".").Append(itemCultureInfo.culture);
}
if (string.Equals(extension, ".resources", StringComparison.OrdinalIgnoreCase))
{
builder.Append(extension);
}
}
else
{
builder.Append(Path.GetFileName(itemCultureInfo.cultureNeutralFilename));
if ((prependCultureAsDirectory && (itemCultureInfo.culture != null)) && (itemCultureInfo.culture.Length > 0))
{
builder.Insert(0, Path.DirectorySeparatorChar);
builder.Insert(0, itemCultureInfo.culture);
}
}
}
return builder.ToString();
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:63,代码来源:CreateVisualBasicManifestResourceName.cs
示例8: GetTypeLibNameForTypeLibAttrs
internal static bool GetTypeLibNameForTypeLibAttrs(TaskLoggingHelper log, System.Runtime.InteropServices.ComTypes.TYPELIBATTR typeLibAttr, out string typeLibName)
{
bool flag;
typeLibName = "";
ITypeLib typeLib = null;
try
{
try
{
System.Runtime.InteropServices.ComTypes.TYPELIBATTR typelibattr = typeLibAttr;
typeLib = (ITypeLib) Microsoft.Build.Tasks.NativeMethods.LoadRegTypeLib(ref typelibattr.guid, typelibattr.wMajorVerNum, typelibattr.wMinorVerNum, typelibattr.lcid);
}
catch (COMException exception)
{
log.LogWarningWithCodeFromResources("ResolveComReference.CannotLoadTypeLib", new object[] { typeLibAttr.guid, typeLibAttr.wMajorVerNum, typeLibAttr.wMinorVerNum, exception.Message });
return false;
}
string typeLibId = log.FormatResourceString("ResolveComReference.TypeLibAttrId", new object[] { typeLibAttr.guid.ToString(), typeLibAttr.wMajorVerNum, typeLibAttr.wMinorVerNum });
flag = GetTypeLibNameForITypeLib(log, typeLib, typeLibId, out typeLibName);
}
finally
{
if (typeLib != null)
{
Marshal.ReleaseComObject(typeLib);
}
}
return flag;
}
示例9: GetDefineConstantsSwitch
/// <summary>
/// Old VS projects had some pretty messed-up looking values for the
/// "DefineConstants" property. It worked fine in the IDE, because it
/// effectively munged up the string so that it ended up being valid for
/// the compiler. We do the equivalent munging here now.
///
/// Basically, we take the incoming string, and split it on comma/semicolon/space.
/// Then we look at the resulting list of strings, and remove any that are
/// illegal identifiers, and pass the remaining ones through to the compiler.
///
/// Note that CSharp does support assigning a value to the constants ... in
/// other words, a constant is either defined or not defined ... it can't have
/// an actual value.
/// </summary>
internal static string GetDefineConstantsSwitch(string originalDefineConstants, TaskLoggingHelper log)
{
if (originalDefineConstants == null)
{
return null;
}
StringBuilder finalDefineConstants = new StringBuilder();
// Split the incoming string on comma/semicolon/space.
string[] allIdentifiers = originalDefineConstants.Split(new char[] { ',', ';', ' ' });
// Loop through all the parts, and for the ones that are legal C# identifiers,
// add them to the outgoing string.
foreach (string singleIdentifier in allIdentifiers)
{
if (SyntaxFacts.IsValidIdentifier(singleIdentifier))
{
// Separate them with a semicolon if there's something already in
// the outgoing string.
if (finalDefineConstants.Length > 0)
{
finalDefineConstants.Append(";");
}
finalDefineConstants.Append(singleIdentifier);
}
else if (singleIdentifier.Length > 0)
{
log.LogWarningWithCodeFromResources("Csc_InvalidParameterWarning", "/define:", singleIdentifier);
}
}
if (finalDefineConstants.Length > 0)
{
return finalDefineConstants.ToString();
}
else
{
// We wouldn't want to pass in an empty /define: switch on the csc.exe command-line.
return null;
}
}
示例10: GetPathOfTypeLib
/*
* Method: GetPathOfTypeLib
*
* Gets the type lib path for given type lib attributes (reused almost verbatim from vsdesigner utils code)
* NOTE: If there's a typelib number at the end of the path, does NOT strip it.
*/
internal static bool GetPathOfTypeLib(TaskLoggingHelper log, bool silent, ref TYPELIBATTR typeLibAttr, out string typeLibPath)
{
// Get which file the type library resides in. If the appropriate
// file cannot be found then a blank string is returned.
typeLibPath = "";
try
{
// Get the path from the registry
// This call has known issues. See http://msdn.microsoft.com/en-us/library/ms221436.aspx for the method and
// here for the fix http://support.microsoft.com/kb/982110. Most users from Win7 or Win2008R2 should have already received this post Win7SP1.
// In Summary: The issue is about calls to The QueryPathOfRegTypeLib function not returning the correct path for a 32-bit version of a
// registered type library in a 64-bit edition of Windows 7 or in Windows Server 2008 R2. It either returns the 64bit path or null.
typeLibPath = NativeMethods.QueryPathOfRegTypeLib(ref typeLibAttr.guid, typeLibAttr.wMajorVerNum, typeLibAttr.wMinorVerNum, typeLibAttr.lcid);
typeLibPath = Environment.ExpandEnvironmentVariables(typeLibPath);
}
catch (COMException ex)
{
if (!silent)
{
log.LogWarningWithCodeFromResources("ResolveComReference.CannotGetPathForTypeLib", typeLibAttr.guid, typeLibAttr.wMajorVerNum, typeLibAttr.wMinorVerNum, ex.Message);
}
return false;
}
if (typeLibPath != null && typeLibPath.Length > 0)
{
// We have to check for NULL here because QueryPathOfRegTypeLib() returns
// a BSTR with a NULL character appended to it.
if (typeLibPath[typeLibPath.Length - 1] == '\0')
{
typeLibPath = typeLibPath.Substring(0, typeLibPath.Length - 1);
}
}
if (typeLibPath != null && typeLibPath.Length > 0)
{
return true;
}
else
{
if (!silent)
{
log.LogWarningWithCodeFromResources("ResolveComReference.CannotGetPathForTypeLib", typeLibAttr.guid, typeLibAttr.wMajorVerNum, typeLibAttr.wMinorVerNum, "");
}
return false;
}
}
示例11: GetTypeLibNameForTypeLibAttrs
/*
* Method: GetTypeLibNameForTypeLibAttrs
*
* Gets the name of given type library.
*/
internal static bool GetTypeLibNameForTypeLibAttrs(TaskLoggingHelper log, bool silent, TYPELIBATTR typeLibAttr, out string typeLibName)
{
typeLibName = "";
ITypeLib typeLib = null;
try
{
// load our type library
try
{
TYPELIBATTR attr = typeLibAttr;
typeLib = (ITypeLib)NativeMethods.LoadRegTypeLib(ref attr.guid, attr.wMajorVerNum, attr.wMinorVerNum, attr.lcid);
}
catch (COMException ex)
{
if (!silent)
{
log.LogWarningWithCodeFromResources("ResolveComReference.CannotLoadTypeLib", typeLibAttr.guid, typeLibAttr.wMajorVerNum, typeLibAttr.wMinorVerNum, ex.Message);
}
return false;
}
string typeLibId = log.FormatResourceString("ResolveComReference.TypeLibAttrId", typeLibAttr.guid.ToString(), typeLibAttr.wMajorVerNum, typeLibAttr.wMinorVerNum);
return GetTypeLibNameForITypeLib(log, silent, typeLib, typeLibId, out typeLibName);
}
finally
{
if (typeLib != null)
Marshal.ReleaseComObject(typeLib);
}
}
示例12: GetTypeLibNameForITypeLib
/*
* Method: GetTypeLibNameForITypeLib
*
* Gets the name of given type library.
*/
internal static bool GetTypeLibNameForITypeLib(TaskLoggingHelper log, bool silent, ITypeLib typeLib, string typeLibId, out string typeLibName)
{
typeLibName = "";
// see if the type library supports ITypeLib2
ITypeLib2 typeLib2 = typeLib as ITypeLib2;
if (typeLib2 == null)
{
// Looks like the type lib doesn't support it. Let's use the Marshal method.
typeLibName = Marshal.GetTypeLibName(typeLib);
return true;
}
// Get the custom attribute. If anything fails then just return the
// type library name.
try
{
object data = null;
typeLib2.GetCustData(ref NativeMethods.GUID_TYPELIB_NAMESPACE, out data);
// if returned namespace is null or its type is not System.String, fall back to the default
// way of getting the type lib name (just to be safe)
if (data == null || string.Compare(data.GetType().ToString(), "system.string", StringComparison.OrdinalIgnoreCase) != 0)
{
typeLibName = Marshal.GetTypeLibName(typeLib);
return true;
}
// Strip off the DLL extension if it's there
typeLibName = (string)data;
if (typeLibName.Length >= 4)
{
if (string.Compare(typeLibName.Substring(typeLibName.Length - 4), ".dll", StringComparison.OrdinalIgnoreCase) == 0)
{
typeLibName = typeLibName.Substring(0, typeLibName.Length - 4);
}
}
}
catch (COMException ex)
{
// If anything fails log a warning and just return the type library name.
if (!silent)
{
log.LogWarningWithCodeFromResources("ResolveComReference.CannotAccessTypeLibName", typeLibId, ex.Message);
}
typeLibName = Marshal.GetTypeLibName(typeLib);
return true;
}
return true;
}
示例13: GeneratePathToTool
/// <summary>
/// This method will take a sdkToolsPath and a toolName and return the path to the tool if it is found and exists.
///
/// First the method will try and find the tool under the sdkToolsPath taking into account the current processor architecture
/// If the tool could not be found the method will try and find the tool under the sdkToolsPath (which should point to the x86 sdk directory).
///
/// Finally if the method has not found the tool yet it will fallback and use the toolslocation helper method to try and find the tool.
/// </summary>
/// <returns>Path including the toolName of the tool if found, null if it is not found</returns>
internal static string GeneratePathToTool(FileExists fileExists, string currentArchitecture, string sdkToolsPath, string toolName, TaskLoggingHelper log, bool logErrorsAndWarnings)
{
// Null until we combine the toolname with the path.
string pathToTool = null;
if (!String.IsNullOrEmpty(sdkToolsPath))
{
string processorSpecificToolDirectory = String.Empty;
try
{
switch (currentArchitecture)
{
// There may not be an arm directory so we will fall back to the x86 tool location
// but if there is then we should try and use it.
case ProcessorArchitecture.ARM:
processorSpecificToolDirectory = Path.Combine(sdkToolsPath, "arm");
break;
case ProcessorArchitecture.AMD64:
processorSpecificToolDirectory = Path.Combine(sdkToolsPath, "x64");
break;
case ProcessorArchitecture.IA64:
processorSpecificToolDirectory = Path.Combine(sdkToolsPath, "ia64");
break;
case ProcessorArchitecture.X86:
default:
processorSpecificToolDirectory = sdkToolsPath;
break;
}
pathToTool = Path.Combine(processorSpecificToolDirectory, toolName);
if (!fileExists(pathToTool))
{
// Try falling back to the x86 location
if (currentArchitecture != ProcessorArchitecture.X86)
{
pathToTool = Path.Combine(sdkToolsPath, toolName);
}
}
else
{
return pathToTool;
}
}
catch (ArgumentException e)
{
// Catch exceptions from path.combine
log.LogErrorWithCodeFromResources("General.SdkToolsPathError", toolName, e.Message);
return null;
}
if (fileExists(pathToTool))
{
return pathToTool;
}
else
{
if (logErrorsAndWarnings)
{
// Log an error indicating we could not find it in the processor specific architecture or x86 locations.
// We could not find the tool at all, lot a error.
log.LogWarningWithCodeFromResources("General.PlatformSDKFileNotFoundSdkToolsPath", toolName, processorSpecificToolDirectory, sdkToolsPath);
}
}
}
else
{
if (logErrorsAndWarnings)
{
log.LogMessageFromResources(MessageImportance.Low, "General.SdkToolsPathNotSpecifiedOrToolDoesNotExist", toolName, sdkToolsPath);
}
}
// Fall back and see if we can find it with the toolsLocation helper methods. This is not optimal because
// the location they are looking at is based on when the Microsoft.Build.Utilities.dll was compiled
// but it is better than nothing.
if (null == pathToTool || !fileExists(pathToTool))
{
pathToTool = FindSDKToolUsingToolsLocationHelper(toolName);
if (pathToTool == null && logErrorsAndWarnings)
{
log.LogErrorWithCodeFromResources("General.SdkToolsPathToolDoesNotExist", toolName, sdkToolsPath, ToolLocationHelper.GetDotNetFrameworkSdkRootRegistryKey(TargetDotNetFrameworkVersion.VersionLatest, VisualStudioVersion.VersionLatest));
}
}
return pathToTool;
}
示例14: DeleteFile
/// <summary>
/// Deletes the state file from disk
/// </summary>
/// <param name="stateFile"></param>
/// <param name="log"></param>
static internal void DeleteFile(string stateFile, TaskLoggingHelper log)
{
try
{
if (stateFile != null && stateFile.Length > 0)
{
if (File.Exists(stateFile))
{
File.Delete(stateFile);
}
}
}
catch (Exception e) when (ExceptionHandling.IsIoRelatedException(e))
{
log.LogWarningWithCodeFromResources("General.CouldNotDeleteStateFile", stateFile, e.Message);
}
}
示例15: SerializeCache
internal virtual void SerializeCache(string stateFile, TaskLoggingHelper log)
{
try
{
if ((stateFile != null) && (stateFile.Length > 0))
{
if (File.Exists(stateFile))
{
File.Delete(stateFile);
}
using (FileStream stream = new FileStream(stateFile, FileMode.CreateNew))
{
new BinaryFormatter().Serialize(stream, this);
}
}
}
catch (Exception exception)
{
if (Microsoft.Build.Shared.ExceptionHandling.NotExpectedException(exception))
{
throw;
}
log.LogWarningWithCodeFromResources("General.CouldNotWriteStateFile", new object[] { stateFile, exception.Message });
}
}