public string GetILMergePath()
        {
            string exePath = null;
            string errMsg;
            var    failedPaths = new List <string>();

            // Look at property containing ILMerge's full path. Supported in ILMerge nuget package 3.0.17 and above.
            if (string.IsNullOrWhiteSpace(ILMergeConsolePath))
            {
                Log.LogWarning("Variable $(ILMergeConsolePath) is not available. For a better experience please make sure you are using the latest version of ilmerge's nuget pakcage.");
            }
            else
            {
                exePath = Path.GetFullPath(ILMergeConsolePath);
                Log.LogMessage($"ILMerge.exe found at $(ILMergeConsolePath): {exePath}");
                return(exePath);
            }

            // look at same directory as this assembly (task dll);
            if (ExeLocationHelper.TryValidateILMergePath(Path.GetDirectoryName(this.GetType().Assembly.Location), out exePath))
            {
                Log.LogMessage($"ILMerge.exe found at (task location): {Path.GetDirectoryName(this.GetType().Assembly.Location)}");
                return(exePath);
            }
            else
            {
                errMsg = $"ILMerge.exe not found at (task location): {Path.GetDirectoryName(this.GetType().Assembly.Location)}";
                failedPaths.Add(errMsg);
                Log.LogMessage(errMsg);
            }

            // look at target dir;
            if (!string.IsNullOrWhiteSpace(TargetDir))
            {
                if (ExeLocationHelper.TryValidateILMergePath(this.TargetDir, out exePath))
                {
                    Log.LogMessage($"ILMerge.exe found at (target dir): {this.TargetDir}");
                    return(exePath);
                }
                else
                {
                    errMsg = $"ILMerge.exe not found at (target dir): {this.TargetDir}";
                    failedPaths.Add(errMsg);
                    Log.LogMessage(errMsg);
                }
            }

            // look for "packages" folder at the solution root and if one is found, look for ILMerge package folder
            if (!string.IsNullOrWhiteSpace(this.SolutionDir))
            {
                if (ExeLocationHelper.TryILMergeInSolutionDir(this.SolutionDir, out exePath))
                {
                    Log.LogMessage($"ILMerge.exe found at (solution dir): {this.SolutionDir}");
                    return(exePath);
                }
                {
                    errMsg = $"ILMerge.exe not found at (solution dir): {this.SolutionDir}";
                    failedPaths.Add(errMsg);
                    Log.LogMessage(errMsg);
                }
            }

            // get the location of the this assembly (task dll) and assumes it is under the packages folder.
            // use this information to determine the possible location of the executable.
            if (ExeLocationHelper.TryLocatePackagesFolder(Log, out exePath))
            {
                Log.LogMessage($"ILMerge.exe found at custom package location: {exePath}");
                return(exePath);
            }
            {
                foreach (var err in failedPaths)
                {
                    Log.LogWarning(err);
                }

                Log.LogWarning($"Unable to determine custom package location or, location was determined but an ILMerge package folder was not found.");
            }

            return(exePath);
        }
Ejemplo n.º 2
0
        public string GetILMergePath()
        {
            string exePath = null;
            string errMsg;
            var    failedPaths = new List <string>();

            // look at same directory as this assembly (task dll);
            if (ExeLocationHelper.TryValidateILMergePath(Path.GetDirectoryName(this.GetType().Assembly.Location), out exePath))
            {
                Log.LogMessage($"ILMerge.exe found at (task location): {Path.GetDirectoryName(this.GetType().Assembly.Location)}");
                return(exePath);
            }
            else
            {
                errMsg = $"ILMerge.exe not found at (task location): {Path.GetDirectoryName(this.GetType().Assembly.Location)}";
                failedPaths.Add(errMsg);
                Log.LogMessage(errMsg);
            }

            // look at target dir;
            if (!string.IsNullOrWhiteSpace(TargetDir))
            {
                if (ExeLocationHelper.TryValidateILMergePath(this.TargetDir, out exePath))
                {
                    Log.LogMessage($"ILMerge.exe found at (target dir): {this.TargetDir}");
                    return(exePath);
                }
                else
                {
                    errMsg = $"ILMerge.exe not found at (target dir): {this.TargetDir}";
                    failedPaths.Add(errMsg);
                    Log.LogMessage(errMsg);
                }
            }

            // look for "packages" folder at the solution root and if one is found, look for ILMerge package folder
            if (!string.IsNullOrWhiteSpace(this.SolutionDir))
            {
                if (ExeLocationHelper.TryILMergeInSolutionDir(this.SolutionDir, out exePath))
                {
                    Log.LogMessage($"ILMerge.exe found at (solution dir): {this.SolutionDir}");
                    return(exePath);
                }
                {
                    errMsg = $"ILMerge.exe not found at (solution dir): {this.SolutionDir}";
                    failedPaths.Add(errMsg);
                    Log.LogMessage(errMsg);
                }
            }

            // get the location of the this assembly (task dll) and assumes it is under the packages folder.
            // use this information to determine the possible location of the executable.
            if (ExeLocationHelper.TryLocatePackagesFolder(Log, out exePath))
            {
                Log.LogMessage($"ILMerge.exe found at custom package location: {exePath}");
                return(exePath);
            }
            {
                foreach (var err in failedPaths)
                {
                    Log.LogWarning(err);
                }

                Log.LogWarning($"Unable to determine custom package location or, location was determined but an ILMerge package folder was not found.");
            }

            return(exePath);
        }