public bool IsDependencyInstalled(CodeGenerationContext context) { if (context == null) { throw new ArgumentNullException("context"); } bool isODataRestierAssemblyReferenced = ProjectReferences.IsAssemblyReferenced(context.ActiveProject, AssemblyVersions.ODataRestierAssemblyName); context.Items[ContextKeys.IsODataRestierAssemblyReferencedKey] = isODataRestierAssemblyReferenced; bool isEntityFrameworkAssemblyReferenced = ProjectReferences.IsAssemblyReferenced(context.ActiveProject, AssemblyVersions.EntityFrameworkAssemblyName); context.Items[ContextKeys.IsEntityFrameworkAssemblyReferencedKey] = isEntityFrameworkAssemblyReferenced; return(isODataRestierAssemblyReferenced && isEntityFrameworkAssemblyReferenced); }
// The parameter 'latestKnownAssemblyVersion' can be null and if yes will be // infered from 'assemblyReferenceName' parameter. // I added that as a parameter to make unit testing easier. internal static void GetPackageFileNameForPackage(CodeGenerationContext context, IEnumerable <IVsPackageMetadata> installedPackages, string packageId, string assemblyReferenceName, Version minSupportedAssemblyReferenceVersion, ref string packageFileName) { if (ProjectReferences.IsAssemblyReferenced(context.ActiveProject, assemblyReferenceName)) { // If the project has reference to MVC version 5.0 or // above the corresponding package versions file is loaded from the file system. IVsPackageMetadata installedPackage = installedPackages. Where(package => String.Equals(packageId, package.Id, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); Version versionForPackageFile; // First try to get the package version and if not fallback to assembly reference version. if (installedPackage == null || !SemanticVersionParser.TryParse(installedPackage.VersionString, out versionForPackageFile)) { // Note: In this scenario where user does not have a package // reference but only has assembly reference, we will end up // using 5.1.0 instead of 5.1.1 version of package file (even // if the assembly reference is the same as the one shipped in 5.1.1) // because the assembly version did not change for 5.1.1 versionForPackageFile = ProjectReferences.GetAssemblyVersion(context.ActiveProject, assemblyReferenceName); } // Version should have been either available from package or atleast the assembly reference. Contract.Assert(versionForPackageFile != null); // For example : If 5.1 is the latest tooling version and if we release just the NuGet packages for a higher version of runtime (may be 5.2), // we will still continue to scaffold the latest tooling version (in this case 5.1). if (versionForPackageFile >= minSupportedAssemblyReferenceVersion && versionForPackageFile <= _latestKnownPackageVersion) { packageFileName = GetPackageVersionsFileName(versionForPackageFile); } } }