예제 #1
0
        public void GetEnvVars()
        {
            IDictionary <string, string> envVars        = CommunicationsUtilities.GetEnvironmentVariables();
            IDictionary referenceVars                   = Environment.GetEnvironmentVariables();
            IDictionary <string, string> referenceVars2 = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            foreach (DictionaryEntry item in referenceVars)
            {
                referenceVars2.Add((string)item.Key, (string)item.Value);
            }

            Helpers.AssertCollectionsValueEqual(envVars, referenceVars2);
        }
예제 #2
0
        public void HandshakesDiffer()
        {
            int numHandshakeOptions           = (int)Math.Pow(2, Enum.GetNames(typeof(HandshakeOptions)).Length - 1);
            Dictionary <long, int> handshakes = new Dictionary <long, int>();

            for (int i = 0; i < numHandshakeOptions; i++)
            {
                long nextKey = CommunicationsUtilities.GetHostHandshake((HandshakeOptions)i);
                if (handshakes.TryGetValue(nextKey, out int collision))
                {
                    _output.WriteLine("There was a collision between {0} and {1}.", collision, i);
                }
                else
                {
                    handshakes.Add(nextKey, i);
                }
            }
            handshakes.Count.ShouldBe(numHandshakeOptions, "two or more combinations of handshake options hashed to the same value");
        }
예제 #3
0
        internal Handshake(HandshakeOptions nodeType)
        {
            const int handshakeVersion = (int)CommunicationsUtilities.handshakeVersion;

            // We currently use 7 bits of this 32-bit integer. Very old builds will instantly reject any handshake that does not start with F5 or 06; slightly old builds always lead with 00.
            // This indicates in the first byte that we are a modern build.
            options = (int)nodeType | (handshakeVersion << 24);
            CommunicationsUtilities.Trace("Building handshake for node type {0}, (version {1}): options {2}.", nodeType, handshakeVersion, options);

            string handshakeSalt = Environment.GetEnvironmentVariable("MSBUILDNODEHANDSHAKESALT");

            CommunicationsUtilities.Trace("Handshake salt is " + handshakeSalt);
            string toolsDirectory = BuildEnvironmentHelper.Instance.MSBuildToolsDirectoryRoot;

            CommunicationsUtilities.Trace("Tools directory root is " + toolsDirectory);
            salt = CommunicationsUtilities.GetHashCode(handshakeSalt + toolsDirectory);
            Version fileVersion = new Version(FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion);

            fileVersionMajor   = fileVersion.Major;
            fileVersionMinor   = fileVersion.Minor;
            fileVersionBuild   = fileVersion.Build;
            fileVersionPrivate = fileVersion.Revision;
            sessionId          = Process.GetCurrentProcess().SessionId;
        }
예제 #4
0
파일: Utilities.cs 프로젝트: enricosada/sln
        /// <summary>
        /// Retrieves properties derived from the current
        /// environment variables.
        /// </summary>
        internal static PropertyDictionary <ProjectPropertyInstance> GetEnvironmentProperties()
        {
            IDictionary <string, string> environmentVariablesBag = CommunicationsUtilities.GetEnvironmentVariables();

            PropertyDictionary <ProjectPropertyInstance> environmentProperties = new PropertyDictionary <ProjectPropertyInstance>(environmentVariablesBag.Count + 2);

            // We set the MSBuildExtensionsPath variables here because we don't want to make them official
            // reserved properties; we need the ability for people to override our default in their
            // environment or as a global property.

#if !FEATURE_INSTALLED_MSBUILD
            string extensionsPath   = BuildEnvironmentHelper.Instance.CurrentMSBuildToolsDirectory;
            string extensionsPath32 = extensionsPath;
#else
            // "MSBuildExtensionsPath32". This points to whatever the value of "Program Files (x86)" environment variable is;
            // but on a 32 bit box this isn't set, and we should use "Program Files" instead.
            string programFiles32   = FrameworkLocationHelper.programFiles32;
            string extensionsPath32 = NativeMethodsShared.IsWindows
                                          ? Path.Combine(programFiles32, ReservedPropertyNames.extensionsPathSuffix)
                                          : programFiles32;
#endif
            environmentProperties.Set(ProjectPropertyInstance.Create(ReservedPropertyNames.extensionsPath32, extensionsPath32, true));

#if !FEATURE_INSTALLED_MSBUILD
            string extensionsPath64 = extensionsPath;
            environmentProperties.Set(ProjectPropertyInstance.Create(ReservedPropertyNames.extensionsPath64, extensionsPath64, true));
#else
            // "MSBuildExtensionsPath64". This points to whatever the value of "Program Files" environment variable is on a
            // 64-bit machine, and is empty on a 32-bit machine.
            if (FrameworkLocationHelper.programFiles64 != null)
            {
                // if ProgramFiles and ProgramFiles(x86) are the same, then this is a 32-bit box,
                // so we only want to set MSBuildExtensionsPath64 if they're not
                string extensionsPath64 = NativeMethodsShared.IsWindows
                                              ? Path.Combine(
                    FrameworkLocationHelper.programFiles64,
                    ReservedPropertyNames.extensionsPathSuffix)
                                              : FrameworkLocationHelper.programFiles64;
                environmentProperties.Set(ProjectPropertyInstance.Create(ReservedPropertyNames.extensionsPath64, extensionsPath64, true));
            }
#endif

#if FEATURE_INSTALLED_MSBUILD
            // MSBuildExtensionsPath:  The way this used to work is that it would point to "Program Files\MSBuild" on both
            // 32-bit and 64-bit machines.  We have a switch to continue using that behavior; however the default is now for
            // MSBuildExtensionsPath to always point to the same location as MSBuildExtensionsPath32.

            bool useLegacyMSBuildExtensionsPathBehavior = !String.IsNullOrEmpty(Environment.GetEnvironmentVariable("MSBUILDLEGACYEXTENSIONSPATH"));

            string programFiles = FrameworkLocationHelper.programFiles;
            string extensionsPath;
            if (useLegacyMSBuildExtensionsPathBehavior)
            {
                extensionsPath = Path.Combine(programFiles, ReservedPropertyNames.extensionsPathSuffix);
            }
            else
            {
                extensionsPath = extensionsPath32;
            }
#endif

            environmentProperties.Set(ProjectPropertyInstance.Create(ReservedPropertyNames.extensionsPath, extensionsPath, true));

            // Windows XP and Windows Server 2003 don't define LocalAppData in their environment.
            // We'll set it here if the environment doesn't have it so projects can reliably
            // depend on $(LocalAppData).
            string localAppData = String.Empty;
            ProjectPropertyInstance localAppDataProp = environmentProperties.GetProperty(ReservedPropertyNames.localAppData);
            if (localAppDataProp != null)
            {
                localAppData = localAppDataProp.EvaluatedValue;
            }

            if (String.IsNullOrEmpty(localAppData))
            {
#if FEATURE_SPECIAL_FOLDERS
                localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
#else
                localAppData = FileUtilities.GetFolderPath(FileUtilities.SpecialFolder.LocalApplicationData);
#endif
            }

            if (String.IsNullOrEmpty(localAppData))
            {
#if FEATURE_SPECIAL_FOLDERS
                localAppData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
#else
                localAppData = FileUtilities.GetFolderPath(FileUtilities.SpecialFolder.ApplicationData);
#endif
            }

            if (String.IsNullOrEmpty(localAppData))
            {
                localAppData = BuildEnvironmentHelper.Instance.CurrentMSBuildToolsDirectory;
            }


            environmentProperties.Set(ProjectPropertyInstance.Create(ReservedPropertyNames.localAppData, localAppData));

            // Add MSBuildUserExtensionsPath at $(LocalAppData)\Microsoft\MSBuild
            string userExtensionsPath = Path.Combine(localAppData, ReservedPropertyNames.userExtensionsPathSuffix);
            environmentProperties.Set(ProjectPropertyInstance.Create(ReservedPropertyNames.userExtensionsPath, userExtensionsPath));

            if (environmentVariablesBag != null)
            {
                foreach (KeyValuePair <string, string> environmentVariable in environmentVariablesBag)
                {
                    // We're going to just skip environment variables that contain names
                    // with characters we can't handle. There's no logger registered yet
                    // when this method is called, so we can't really log anything.
                    string environmentVariableName = environmentVariable.Key;

                    if (XmlUtilities.IsValidElementName(environmentVariableName) &&
                        XMakeElements.IllegalItemPropertyNames[environmentVariableName] == null &&
                        !ReservedPropertyNames.IsReservedProperty(environmentVariableName))
                    {
                        ProjectPropertyInstance environmentProperty = ProjectPropertyInstance.Create(environmentVariableName, environmentVariable.Value);

                        environmentProperties.Set(environmentProperty);
                    }
                    else
                    {
                        // The name was invalid, so we just didn't add the environment variable.
                        // That's fine, continue for the next one.
                    }
                }
            }

            return(environmentProperties);
        }