static bool CheckSLMigrationLicense(ILogger logger, string activationAppPath, HashSet <string> flags) { //if the user tries to use the SL Migration edition, we check whether it is allowed or not here even though it has nothing to do with the Xaml Preprocessor because it is the only thing that the user cannot remove from the targets. if (!ActivationHelpers.IsFeatureEnabled(Constants.ENTERPRISE_EDITION_FEATURE_ID, flags) && !ActivationHelpers.IsFeatureEnabled(Constants.SL_MIGRATION_EDITION_FEATURE_ID, flags)) { // Display the ActivationApp: string explanationToDisplayInActivationApp = string.Format("You need the Silverlight Migration Edition in order to compile Silverlight-compatible projects."); string explanationToDisplayInErrorsWindow = explanationToDisplayInActivationApp + " It can be obtained from http://www.cshtml5.com - Please rebuild the project to try again."; ActivationHelpers.DisplayActivationApp(activationAppPath, Constants.SL_MIGRATION_EDITION_FEATURE_ID, explanationToDisplayInActivationApp); // If we are in trial mode, we can continue without displaying any errors, otherwise we must stop compilation and raise the error: int unused; if (TrialHelpers.IsTrial(Constants.SL_MIGRATION_EDITION_FEATURE_ID, out unused) == TrialHelpers.TrialStatus.Running) //Note: we don't check for the enterprise edition since there is no trial for this edition. { //do nothing return(true); } else { logger.WriteError(explanationToDisplayInErrorsWindow); return(false); } } return(true); }
public static bool Execute(string sourceAssembly, string activationAppPath, string flagsString, ILogger logger) { string operationName = "C#/XAML for HTML5: CompatibilityAnalyzer"; try { List <UnsupportedMethodInfo> outputListOfUnsupportedMethods = new List <UnsupportedMethodInfo>(); AssemblyDefinition assembly = LoadAssembly(sourceAssembly); AssemblyDefinition[] assemblies = new AssemblyDefinition[] { assembly }; HashSet <string> flags = (flagsString != null ? new HashSet <string>(flagsString.Split(';')) : new HashSet <string>()); var checkIfUnsupportedMethods = new CheckingThatNoUnsupportedMethodIsCalled(); checkIfUnsupportedMethods.InitializeListOfSupportedMethods(new List <string>(), logger); //-------------------------------------------- // CHECK FOR UNSUPPORTED METHODS: //-------------------------------------------- checkIfUnsupportedMethods.Check(assemblies, "", "", "mscorlib", flags, whatToDoWhenNotSupportedMethodFound: (unsupportedMethodInfo) => { #if REQUIRE_ACTIVATION_FOR_USING_CERTAIN_METHODS // First, we distinguish whether the reason why the method is not allowed is because it requires a license (aka a "missing feature"), or because it is not supported: if (unsupportedMethodInfo.RequiresMissingFeature) { // Cause the popup to appear that says that a license is required: logger.SetRequiresMissingFeature(unsupportedMethodInfo.MissingFeatureId, unsupportedMethodInfo.MessageForMissingFeature); // Cause an error to appear and the compilation to abort: if (!unsupportedMethodInfo.IsInValidTrialMode) { logger.WriteError(unsupportedMethodInfo.ExplanationToDisplayInErrorsWindow); } } else { // Cause an error to appear and the compilation to abort: logger.WriteError(unsupportedMethodInfo.ExplanationToDisplayInErrorsWindow); outputListOfUnsupportedMethods.Add(unsupportedMethodInfo); } #else // Cause an error to appear and the compilation to abort: logger.WriteError(unsupportedMethodInfo.ExplanationToDisplayInErrorsWindow); outputListOfUnsupportedMethods.Add(unsupportedMethodInfo); #endif }); #if REQUIRE_ACTIVATION_FOR_USING_CERTAIN_METHODS // If a feature is missing (eg. the "Professional Edition" is required), display the window for activation: if (logger.RequiresMissingFeature) { ActivationHelpers.DisplayActivationApp(activationAppPath, logger.MissingFeatureId, logger.MessageForMissingFeature); } #endif bool isSuccess = !logger.HasErrors; return(isSuccess); } catch (Exception ex) { logger.WriteError(operationName + " failed: " + ex.ToString()); return(false); } }
public static bool Check(Microsoft.Build.Framework.ITaskItem[] references, string allowedReferencesAsString, string activationAppPath, string flagsString, ILogger logger, bool isBridgeBasedVersion, string nameOfAssembliesThatDoNotContainUserCode, string projectDir, string referencesPaths, string typeForwardingAssemblyPath) { List <string> referencesThatAreOK = new List <string>(); List <string> referencesThatAreNotCompatible = new List <string>(); #if REQUIRE_PRO_EDITION_FOR_REFERENCING_ASSEMBLIES List <string> referencesThatRequireToUpgradeToTheProEdition = new List <string>(); #endif List <string> referencesThatRequireNewerVersionOfTheCompiler = new List <string>(); string overall_minimumRequiredCompilerVersionFriendlyNameIfAny = null; HashSet <string> flags = (flagsString != null ? new HashSet <string>(flagsString.Split(';')) : new HashSet <string>()); foreach (Microsoft.Build.Framework.ITaskItem taskItem in (references ?? new Microsoft.Build.Framework.ITaskItem[] { })) { string referencedName = GetAssemblyNameFromIdentity(taskItem.GetMetadata("identity")); //Note: "GetMetadata" and "GetAssemblyName" never return null. string referencedHintPathIfAny = taskItem.GetMetadata("HintPath"); //Note: "GetMetadata" never return null. ResultEnum result; string minimumRequiredCompilerVersionFriendlyNameIfAny; IsReferenceAcceptable(referencedName, referencedHintPathIfAny, allowedReferencesAsString, flags, isBridgeBasedVersion, nameOfAssembliesThatDoNotContainUserCode, projectDir, referencesPaths, typeForwardingAssemblyPath, out result, out minimumRequiredCompilerVersionFriendlyNameIfAny); switch (result) { case ResultEnum.ReferenceIsOK: referencesThatAreOK.Add(referencedName); break; case ResultEnum.ReferenceIsNotCompatible: referencesThatAreNotCompatible.Add(referencedName); break; case ResultEnum.ReferenceRequiresNewerVersionOfTheCompiler: referencesThatRequireNewerVersionOfTheCompiler.Add(referencedName); overall_minimumRequiredCompilerVersionFriendlyNameIfAny = minimumRequiredCompilerVersionFriendlyNameIfAny; break; #if REQUIRE_PRO_EDITION_FOR_REFERENCING_ASSEMBLIES case ResultEnum.ReferenceRequiresToUpgradeToTheProEdition: referencesThatRequireToUpgradeToTheProEdition.Add(referencedName); break; #endif default: throw new NotSupportedException(); } } if (referencesThatAreNotCompatible.Count == 1) { logger.WriteError(string.Format("Please remove the reference \"{0}\" from the Project references. - Note: a CSHTML5 project can only reference assemblies compiled with CSHTML5. Sometimes Visual Studio automatically adds references such as \"System\" but those references should be removed. Other errors below can be ignored.", referencesThatAreNotCompatible[0])); return(false); } else if (referencesThatAreNotCompatible.Count > 1) { logger.WriteError(string.Format("Please remove the following references from the Project references: {0} - Note: a CSHTML5 project can only reference assemblies compiled with CSHTML5. Sometimes Visual Studio automatically adds references such as \"System\" but those references should be removed. Other errors below can be ignored.", string.Join(", ", referencesThatAreNotCompatible))); return(false); } else if (referencesThatRequireNewerVersionOfTheCompiler.Count > 0) { if (referencesThatRequireNewerVersionOfTheCompiler.Count == 1) { logger.WriteError(string.Format("The referenced assembly '{1}' requires a newer version of the CSHTML5 compiler ({0} or newer). You can download it from: http://www.cshtml5.com", overall_minimumRequiredCompilerVersionFriendlyNameIfAny ?? "", referencesThatRequireNewerVersionOfTheCompiler[0])); } else { logger.WriteError(string.Format("The following referenced assemblies require a newer version of the CSHTML5 compiler ({0} or newer): {1}", overall_minimumRequiredCompilerVersionFriendlyNameIfAny ?? "", string.Join(", ", referencesThatRequireNewerVersionOfTheCompiler))); } return(false); } #if REQUIRE_PRO_EDITION_FOR_REFERENCING_ASSEMBLIES else if (referencesThatRequireToUpgradeToTheProEdition.Count > 0) { // Display the ActivationApp: string explanationToDisplayInActivationApp = string.Format("Referencing compiled DLLs such as '{0}' requires the Professional Edition of CSHTML5. You can work around this limitation if you have the source code of '{0}': just add the project to the solution and reference it instead of referencing the compiled DLL. With the Free Edition, projects can reference other projects in the same solution, but they cannot reference external compiled DLLs. Upgrade to the Pro Edition to remove all the limitations.", referencesThatRequireToUpgradeToTheProEdition[0] + ".dll"); //string explanationToDisplayInActivationApp = string.Format("With the Free Edition, projects can reference other projects in the same solution, but referencing a compiled DLL such as \"{0}\" requires the Professional Edition of C#/XAML for HTML5.", referencesThatRequireToUpgradeToTheProEdition[0] + ".dll"); string explanationToDisplayInErrorsWindow = explanationToDisplayInActivationApp + " It can be obtained from http://www.cshtml5.com - Please rebuild the project to try again."; ActivationHelpers.DisplayActivationApp(activationAppPath, Constants.PROFESSIONAL_EDITION_FEATURE_ID, explanationToDisplayInActivationApp); // If we are in trial mode, we can continue without displaying any errors, otherwise we must stop compilation and raise the error: int unused; if (TrialHelpers.IsTrial(Constants.SL_MIGRATION_EDITION_FEATURE_ID, out unused) == TrialHelpers.TrialStatus.Running) { return(true); } else { if (TrialHelpers.IsTrial(Constants.PROFESSIONAL_EDITION_FEATURE_ID, out unused) == TrialHelpers.TrialStatus.Running) { return(true); } else { logger.WriteError(explanationToDisplayInErrorsWindow); return(false); } } } #endif else { return(true); } }