Ejemplo n.º 1
0
        /// <summary>
        /// Gets the output path for a specified VisualStudio project. The output path is relative
        /// to the directory where the project file is located.
        /// </summary>
        /// <param name="buildConfiguration">The build configuration.</param>
        /// <returns>
        /// The output path or <c>null</c> if the project is not compatible.
        /// </returns>
        /// <exception cref="ArgumentException">The method could not extract the data from the project file.</exception>
        public LocalPath GetProjectOutputPath(string buildConfiguration)
        {
            // skip non-C# projects
            if (ProjectTypeGuid != VSProjectType.CSharpProjectType.ProjectTypeGuid && ProjectTypeGuid != VSProjectType.NewCSharpProjectType.ProjectTypeGuid)
            {
                return(null);
            }

            // find the project configuration
            string condition = string.Format(
                CultureInfo.InvariantCulture,
                "'$(Configuration)|$(Platform)' == '{0}|AnyCPU'",
                buildConfiguration);
            VSProjectConfiguration projectConfiguration = ProjectDetails.FindConfiguration(condition);

            if (projectConfiguration == null)
            {
                string message = string.Format(
                    CultureInfo.InvariantCulture,
                    "Could not find '{0}' configuration for the project '{1}'.",
                    condition,
                    ProjectName);

                throw new ArgumentException(message);
            }

            if (projectConfiguration.Properties.ContainsKey("OutputPath") == false)
            {
                string message = string.Format(
                    CultureInfo.InvariantCulture,
                    "Missing OutputPath for the '{0}' configuration of the project '{1}'.",
                    buildConfiguration,
                    ProjectName);

                throw new ArgumentException(message);
            }

            return(new LocalPath(projectConfiguration.Properties["OutputPath"]));
        }