Example #1
0
 public AssemblyFileReference(AssemblyInfo assemblyInfo, SolutionDeploymentTargetType deploymentTarget)
 {
     this.DeploymentTarget          = deploymentTarget;
     this.DeploymentTargetSpecified = true;
     this.Location          = assemblyInfo.Key;
     this.AssemblyObject    = null;
     this.FileHandle        = assemblyInfo.FileHandle;
     this.ManagedAssembly   = assemblyInfo.Managed;
     this.ResourceAssembly  = assemblyInfo.Resource;
     this.ReferenceAssembly = assemblyInfo.Reference;
 }
        private bool AssemblyLocationCheck(AssemblyInfo info)
        {
            bool result = true;
            SolutionDeploymentTargetType targetType = GetDeploymentTarget(info.TargetType);

            if (!info.Managed && targetType == SolutionDeploymentTargetType.GlobalAssemblyCache)
            {
                result = false;
                Log.Error("The assembly " + info.FileHandle.FullName + " is unmanaged. The assembly will be excluded from the WSP package!");
            }

            return(result);
        }
        private void FindAssembliesInDirectory(DirectoryInfo parentDir, SolutionDeploymentTargetType targetType, Dictionary <string, AssemblyInfo> assembliesFound)
        {
            foreach (FileInfo dllFileInfo in parentDir.GetFiles("*.dll"))
            {
                if (FileProvider.IncludeFile(dllFileInfo))
                {
                    AddCandidateAssembly(dllFileInfo, targetType, assembliesFound);
                }
            }

            foreach (DirectoryInfo childDir in FileProvider.GetDirectories(parentDir))
            {
                FindAssembliesInDirectory(childDir, targetType, assembliesFound);
            }
        }
        private void AddCandidateAssembly(FileInfo candidateAssemblyFileHandle, SolutionDeploymentTargetType targetType, Dictionary <string, AssemblyInfo> assembliesFound)
        {
            // Create the asseblyInfo object form the file
            AssemblyInfo candidateAssemblyInfo = new AssemblyInfo(candidateAssemblyFileHandle, targetType);

            // Do not include Microsoft Assemblies and WSPBuilder, however include CabLib.dll
            if (candidateAssemblyInfo.IsUserAssembly)
            {
                if (AssemblyLocationCheck(candidateAssemblyInfo))
                {
                    if (MultipleAssemblyCheck(candidateAssemblyInfo, assembliesFound))
                    {
                        assembliesFound.Add(candidateAssemblyInfo.Key, candidateAssemblyInfo);
                    }
                }
            }
        }
        public void FindAssemblies(DirectoryInfo parentDir, Dictionary <string, AssemblyInfo> assembliesFound)
        {
            // First probe the bin\debug or bin\release directories
            // HACK: To support WSPBuilder Extensions the bin folder is now probed for assemblies.
            // However only the newest assemblies are used.
            string binFolder = Config.Current.ProjectPath + @"\bin";

            if (Directory.Exists(binFolder))
            {
                DirectoryInfo projectDllPathDir = new DirectoryInfo(binFolder);
                if (FileProvider.IncludeDir(projectDllPathDir))
                {
                    SolutionDeploymentTargetType targetType = SolutionDeploymentTargetType.GlobalAssemblyCache;
                    if (Config.Current.BuildMode == BuildModeType.Debug)
                    {
                        targetType = SolutionDeploymentTargetType.WebApplication;
                    }
                    else
                    {
                        _gacDeployment = true;
                    }

                    // Only use them if they are newer!
                    FindAssembliesInDirectory(projectDllPathDir, targetType, assembliesFound);
                }
            }

            // Probe the GAC
            if (FileProvider.IncludeDir(Config.Current.DirGAC))
            {
                // Only use them if they are newer!
                FindAssembliesInDirectory(Config.Current.DirGAC, SolutionDeploymentTargetType.GlobalAssemblyCache, assembliesFound);
                _gacDeployment = true;
            }

            // Probe the 80\Bin
            if (FileProvider.IncludeDir(Config.Current.DirBin))
            {
                // Only use them if they are newer!
                FindAssembliesInDirectory(Config.Current.DirBin, SolutionDeploymentTargetType.WebApplication, assembliesFound);
            }

            // Wait to specify the ResetWebServer to after that _gacDeployment have been set.
            this.Solution.ResetWebServer          = this.ResetWebServer;
            this.Solution.ResetWebServerSpecified = this.ResetWebServerSpecified;
        }
        /// <summary>
        /// Creates a AssemblyFileReference object based on the parameters.
        /// It will also auto build the SafeControl objects.
        /// </summary>
        private AssemblyFileReference CreateAssemblyFileReference(AssemblyInfo assemblyInfo)
        {
            AssemblyFileReference assemblyFileReference = null;

            if (!assemblyInfo.Resource)
            {
                if (!assemblyInfo.Reference)
                {
                    if (assemblyInfo.Managed)
                    {
                        // Create normal dll reference
                        assemblyFileReference = CreateManagedAssemblyFileReference(assemblyInfo);
                    }
                    else
                    {
                        // Create Unmanaged reference
                        assemblyFileReference = new AssemblyFileReference(assemblyInfo, SolutionDeploymentTargetType.WebApplication);
                        Log.Verbose(string.Format("Unmanaged Assembly added: {0}", assemblyInfo.Key));
                    }
                }
                else
                {
                    // Add the assembly as a ResourceDLL
                    assemblyFileReference = new AssemblyFileReference(assemblyInfo, GetDeploymentTarget(assemblyInfo.TargetType));
                    Log.Verbose(string.Format("Reference Assembly added: {0}", assemblyInfo.Key));
                }
            }
            else
            {
                // Create Resource reference
                SolutionDeploymentTargetType targetType = (assemblyInfo.Managed) ? assemblyInfo.TargetType : SolutionDeploymentTargetType.WebApplication;
                assemblyFileReference = new AssemblyFileReference(assemblyInfo, targetType);
                Log.Verbose(string.Format("Resource Assembly added: {0}", assemblyInfo.Key));
            }

            return(assemblyFileReference);
        }
Example #7
0
        public AssemblyInfo(FileInfo assemblyFileHandle, SolutionDeploymentTargetType targetType)
        {
            this.TargetType = targetType;

            // Get e.g. mytest.dll or en-US\mytest.resource.dll
            this.Key        = assemblyFileHandle.Name;
            this.FileHandle = assemblyFileHandle;

            if (this.Key.EndsWith(".Resources.dll", StringComparison.InvariantCultureIgnoreCase))
            {
                this.Key      = assemblyFileHandle.Directory.Name + @"\" + assemblyFileHandle.Name;
                this.Resource = true;
            }

            // If the assembly is found in a References folder, then do not refect on it for safecontrols.
            string dirName = assemblyFileHandle.Directory.Name;

            if ("Reference".Equals(dirName, StringComparison.OrdinalIgnoreCase) || "References".Equals(dirName, StringComparison.OrdinalIgnoreCase))
            {
                this.Reference = true;
            }

            try
            {
                this.Name = AssemblyName.GetAssemblyName(this.FileHandle.FullName);
            }
            catch (BadImageFormatException imageEx)
            {
                // Check if the assembly is unmanage like Resource dlls
                int hrResult = Marshal.GetHRForException(imageEx);
                if (hrResult != AssemblyStore.COR_E_ASSEMBLYEXPECTED)
                {
                    this.Managed = false;
                }
            }
        }
        private SolutionDeploymentTargetType GetDeploymentTarget(SolutionDeploymentTargetType recommendedTagetType)
        {
            SolutionDeploymentTargetType result;

            if ("GAC".Equals(DeploymentTarget, StringComparison.InvariantCultureIgnoreCase))
            {
                result = SolutionDeploymentTargetType.GlobalAssemblyCache;
            }
            else
            if ("BIN".Equals(DeploymentTarget, StringComparison.InvariantCultureIgnoreCase))
            {
                result = SolutionDeploymentTargetType.WebApplication;
            }
            else
            if ("AUTO".Equals(DeploymentTarget, StringComparison.InvariantCultureIgnoreCase))
            {
                result = recommendedTagetType;
            }
            else
            {
                throw new ApplicationException("Invalid value '" + DeploymentTarget + "' for key '" + DEPLOYMENTTARGET + "'. Has to be (GAC|BIN|Auto)");
            }
            return(result);
        }