Esempio n. 1
0
        /// <summary>
        /// Given a project <paramref name="name"/> located in <paramref name="outputDirectory"/> try to extract the
        /// ProjectGuid setting. If file does not exist or does not contain this property, a new Guid is generated.
        /// </summary>
        /// <param name="outputDirectory">Location of the project <paramref name="name"/></param>
        /// <param name="name">Name on disk of the project file</param>
        /// <param name="guid">Existing Guid for the project, otherwise a new one</param>
        private static void GetExistingGuid(string outputDirectory, string name, out Guid guid)
        {
            // Initialize to new Guid to avoid complex logic after.
            guid = Guid.NewGuid();

            try
            {
                Microsoft.Build.Evaluation.Project p = new Microsoft.Build.Evaluation.Project(Path.Combine(outputDirectory, name));

                var property = p.Properties.Where((prop => prop.Name == "ProjectGuid")).FirstOrDefault();
                if (property != null)
                {
                    Guid.TryParse(property.EvaluatedValue, out guid);
                }
            }
            catch (Exception)
            {
                // Ignore exception
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Given a project <paramref name="name"/> located in <paramref name="outputDirectory"/> try to extract the 
        /// ProjectGuid setting. If file does not exist or does not contain this property, a new Guid is generated.
        /// </summary>
        /// <param name="outputDirectory">Location of the project <paramref name="name"/></param>
        /// <param name="name">Name on disk of the project file</param>
        /// <param name="guid">Existing Guid for the project, otherwise a new one</param>
        private static void GetExistingGuid(string outputDirectory, string name, out Guid guid)
        {
            // Initialize to new Guid to avoid complex logic after.
            guid = Guid.NewGuid();

            try
            {
                Microsoft.Build.Evaluation.Project p = new Microsoft.Build.Evaluation.Project(Path.Combine(outputDirectory, name));

                var property = p.Properties.Where((prop => prop.Name == "ProjectGuid")).FirstOrDefault();
                if (property != null)
                {
                    Guid.TryParse(property.EvaluatedValue, out guid);
                }
            }
            catch (Exception)
            {
                // Ignore exception
            }
        }