コード例 #1
0
		public void ItemsAndProperties ()
		{
            string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
  <ItemGroup>
    <X Condition='false' Include='bar.txt' />
    <X Include='foo.txt'>
      <M>m</M>
      <N>=</N>
    </X>
  </ItemGroup>
  <PropertyGroup>
    <P Condition='false'>void</P>
    <P Condition='true'>valid</P>
  </PropertyGroup>
</Project>";
            var xml = XmlReader.Create (new StringReader(project_xml));
            var root = ProjectRootElement.Create (xml);
            var proj = new ProjectInstance (root);
            var item = proj.Items.First ();
			Assert.AreEqual ("foo.txt", item.EvaluatedInclude, "#1");
			var prop = proj.Properties.First (p => p.Name=="P");
			Assert.AreEqual ("valid", prop.EvaluatedValue, "#2");
			Assert.IsNotNull (proj.GetProperty ("MSBuildProjectDirectory"), "#3");
			Assert.AreEqual ("4.0", proj.ToolsVersion, "#4");
		}
コード例 #2
0
        public static void AssertPropertyDoesNotExist(ProjectInstance projectInstance, string propertyName)
        {
            ProjectPropertyInstance propertyInstance = projectInstance.GetProperty(propertyName);

            string value = propertyInstance == null ? null : propertyInstance.EvaluatedValue;

            Assert.IsNull(propertyInstance, "Not expecting the property to exist. Property: {0}, Value: {1}", propertyName, value);
        }
コード例 #3
0
        protected string ReadPropertyString(MSB.Execution.ProjectInstance executedProject, string executedPropertyName, string evaluatedPropertyName)
        {
            var executedProperty = executedProject.GetProperty(executedPropertyName);

            if (executedProperty != null)
            {
                return(executedProperty.EvaluatedValue);
            }

            var evaluatedProperty = _loadedProject.GetProperty(evaluatedPropertyName);

            if (evaluatedProperty != null)
            {
                return(evaluatedProperty.EvaluatedValue);
            }

            return(null);
        }
コード例 #4
0
ファイル: ProjectConfig.cs プロジェクト: yangfan79/MPFProj10
        protected virtual MSBuildExecution.ProjectPropertyInstance GetMsBuildProperty(string propertyName, _PersistStorageType storageType, bool resetCache)
        {
            MSBuildExecution.ProjectInstance requestedConfig = storageType == _PersistStorageType.PST_PROJECT_FILE ? currentConfig : currentUserConfig;
            if (resetCache || requestedConfig == null)
            {
                // Get properties for current configuration from project file and cache it
                this._project.SetConfiguration(this.ConfigName, this.Platform);
                this._project.BuildProject.ReevaluateIfNecessary();
                if (this._project.UserBuildProject != null)
                {
                    this._project.UserBuildProject.ReevaluateIfNecessary();
                }

                // Create a snapshot of the evaluated project in its current state
                this.currentConfig = this._project.BuildProject.CreateProjectInstance();
                if (this._project.UserBuildProject != null)
                {
                    this.currentUserConfig = this._project.UserBuildProject.CreateProjectInstance();
                }

                requestedConfig = storageType == _PersistStorageType.PST_PROJECT_FILE ? currentConfig : currentUserConfig;

                // Restore configuration
                _project.SetCurrentConfiguration();
            }

            if (requestedConfig == null)
            {
                if (storageType == _PersistStorageType.PST_PROJECT_FILE)
                {
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, SR.GetString(SR.FailedToRetrieveProperties, CultureInfo.CurrentUICulture), propertyName));
                }

                // user build projects aren't essential
                return(null);
            }

            // return property asked for
            return(requestedConfig.GetProperty(propertyName));
        }
コード例 #5
0
        /// <summary>
        /// Add a PropertyGroup to the project for a particular Asp.Net configuration.  This PropertyGroup
        /// will have the correct values for all the Asp.Net properties for this project and this configuration.
        /// </summary>
        private void AddPropertyGroupForAspNetConfiguration
            (
            ProjectInstance traversalProject,
            ProjectInstance metaprojectInstance,
            ProjectInSolution project,
            string configurationName,
            AspNetCompilerParameters aspNetCompilerParameters,
            string solutionFile
            )
        {
            // If the configuration doesn't match, don't add the properties.
            if (!traversalProject.EvaluateCondition(String.Format(CultureInfo.InvariantCulture, " '$(AspNetConfiguration)' == '{0}' ", EscapingUtilities.Escape(configurationName))))
            {
                return;
            }

            // Add properties into the property group for each of the AspNetCompiler properties.
            // REVIEW: SetProperty takes an evaluated value.  Are we doing the right thing here?
            metaprojectInstance.SetProperty(GenerateSafePropertyName(project, "AspNetVirtualPath"), EscapingUtilities.Escape(aspNetCompilerParameters.aspNetVirtualPath));
            metaprojectInstance.SetProperty(GenerateSafePropertyName(project, "AspNetPhysicalPath"), EscapingUtilities.Escape(aspNetCompilerParameters.aspNetPhysicalPath));
            metaprojectInstance.SetProperty(GenerateSafePropertyName(project, "AspNetTargetPath"), EscapingUtilities.Escape(aspNetCompilerParameters.aspNetTargetPath));
            metaprojectInstance.SetProperty(GenerateSafePropertyName(project, "AspNetForce"), EscapingUtilities.Escape(aspNetCompilerParameters.aspNetForce));
            metaprojectInstance.SetProperty(GenerateSafePropertyName(project, "AspNetUpdateable"), EscapingUtilities.Escape(aspNetCompilerParameters.aspNetUpdateable));
            metaprojectInstance.SetProperty(GenerateSafePropertyName(project, "AspNetDebug"), EscapingUtilities.Escape(aspNetCompilerParameters.aspNetDebug));
            metaprojectInstance.SetProperty(GenerateSafePropertyName(project, "AspNetKeyFile"), EscapingUtilities.Escape(aspNetCompilerParameters.aspNetKeyFile));
            metaprojectInstance.SetProperty(GenerateSafePropertyName(project, "AspNetKeyContainer"), EscapingUtilities.Escape(aspNetCompilerParameters.aspNetKeyContainer));
            metaprojectInstance.SetProperty(GenerateSafePropertyName(project, "AspNetDelaySign"), EscapingUtilities.Escape(aspNetCompilerParameters.aspNetDelaySign));
            metaprojectInstance.SetProperty(GenerateSafePropertyName(project, "AspNetAPTCA"), EscapingUtilities.Escape(aspNetCompilerParameters.aspNetAPTCA));
            metaprojectInstance.SetProperty(GenerateSafePropertyName(project, "AspNetFixedNames"), EscapingUtilities.Escape(aspNetCompilerParameters.aspNetFixedNames));

            string aspNetPhysicalPath = aspNetCompilerParameters.aspNetPhysicalPath;
            if (!String.IsNullOrEmpty(aspNetPhysicalPath))
            {
                // Trim the trailing slash if one exists.
                if (
                        (aspNetPhysicalPath[aspNetPhysicalPath.Length - 1] == Path.AltDirectorySeparatorChar) ||
                        (aspNetPhysicalPath[aspNetPhysicalPath.Length - 1] == Path.DirectorySeparatorChar)
                    )
                {
                    aspNetPhysicalPath = aspNetPhysicalPath.Substring(0, aspNetPhysicalPath.Length - 1);
                }

                // This gets us the last folder in the physical path.
                string lastFolderInPhysicalPath = null;

                try
                {
                    lastFolderInPhysicalPath = Path.GetFileName(aspNetPhysicalPath);
                }
                catch (Exception e)
                {
                    if (ExceptionHandling.NotExpectedException(e))
                    {
                        throw;
                    }

                    ProjectFileErrorUtilities.VerifyThrowInvalidProjectFile
                        (
                        false,
                        "SubCategoryForSolutionParsingErrors",
                        new BuildEventFileInfo(solutionFile),
                        e,
                        "SolutionParseInvalidProjectFileName",
                        project.RelativePath,
                        e.Message
                        );
                }

                if (!String.IsNullOrEmpty(lastFolderInPhysicalPath))
                {
                    // If there is a global property called "OutDir" set, that means the caller is trying to 
                    // override the AspNetTargetPath.  What we want to do in this case is concatenate:
                    // $(OutDir) + "\_PublishedWebsites" + (the last portion of the folder in the AspNetPhysicalPath).
                    if (traversalProject.EvaluateCondition(" '$(OutDir)' != '' "))
                    {
                        string outDirValue = String.Empty;
                        ProjectPropertyInstance outdir = metaprojectInstance.GetProperty("OutDir");

                        if (outdir != null)
                        {
                            outDirValue = ProjectInstance.GetPropertyValueEscaped(outdir);
                        }

                        // Make sure the path we are appending to has no leading slash to prevent double slashes.
                        string publishWebsitePath = EscapingUtilities.Escape(WebProjectOverrideFolder) + Path.DirectorySeparatorChar + EscapingUtilities.Escape(lastFolderInPhysicalPath) + Path.DirectorySeparatorChar;

                        metaprojectInstance.SetProperty
                            (
                            GenerateSafePropertyName(project, "AspNetTargetPath"),
                            outDirValue + publishWebsitePath
                            );
                    }
                }
            }
        }
コード例 #6
0
 private static void AssertAnalysisTargetsAreImported(ProjectInstance projectInstance)
 {
     ProjectPropertyInstance propertyInstance = projectInstance.GetProperty(DummyAnalysisTargetsMarkerProperty);
     Assert.IsNotNull(propertyInstance, "Failed to import the SonarQube Analysis targets");
 }
コード例 #7
0
 private static void AssertAnalysisTargetsAreNotImported(ProjectInstance projectInstance)
 {
     ProjectPropertyInstance propertyInstance = projectInstance.GetProperty(DummyAnalysisTargetsMarkerProperty);
     Assert.IsNull(propertyInstance, "SonarQube Analysis targets should not have been imported");
 }
コード例 #8
0
ファイル: ProjectNode.cs プロジェクト: sharwell/MPFProj10
 protected static ProjectPropertyInstance GetMsBuildProperty(ProjectInstance projectInstance, string propertyName)
 {
     return projectInstance.GetProperty(propertyName);
 }
コード例 #9
0
		public void ConditionalExpression ()
		{
			string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
	<PropertyGroup>
		<NoCompilerStandardLib>true</NoCompilerStandardLib>
                <ResolveAssemblyReferencesDependsOn>$(ResolveAssemblyReferencesDependsOn);_AddCorlibReference</ResolveAssemblyReferencesDependsOn>
        </PropertyGroup>
</Project>";
			var xml = XmlReader.Create (new StringReader (project_xml));
			var root = ProjectRootElement.Create (xml);
			root.FullPath = "ProjectInstanceTest.ConditionalExpression.proj";
			var proj = new ProjectInstance (root);
			var p = proj.GetProperty ("ResolveAssemblyReferencesDependsOn");
			Assert.IsNotNull (p, "#1");
			Assert.AreEqual (";_AddCorlibReference", p.EvaluatedValue, "#2");
		}
コード例 #10
0
		public void Choose ()
		{
			string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
  <Choose>
    <When Condition="" '$(DebugSymbols)' != '' "">
      <PropertyGroup>
        <DebugXXX>True</DebugXXX>
      </PropertyGroup>
    </When>
    <Otherwise>
      <PropertyGroup>
        <DebugXXX>False</DebugXXX>
      </PropertyGroup>
    </Otherwise>
  </Choose>
</Project>";
			var xml = XmlReader.Create (new StringReader (project_xml));
			var root = ProjectRootElement.Create (xml);
			root.FullPath = "ProjectInstanceTest.Choose.proj";
			var proj = new ProjectInstance (root);
			var p = proj.GetProperty ("DebugXXX");
			Assert.IsNotNull (p, "#1");
			Assert.AreEqual ("False", p.EvaluatedValue, "#2");
		}
コード例 #11
0
		public void EvaluatePropertyWithQuotation ()
		{
			string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
  <ItemGroup>
    <Foo Include='abc/xxx.txt' />
  </ItemGroup>
  <PropertyGroup>
    <B>foobar</B>
  </PropertyGroup>
  <Target Name='default'>
    <CreateProperty Value=""@(Foo->'%(Filename)%(Extension)')"">
      <Output TaskParameter='Value' PropertyName='P' />
    </CreateProperty>
    <CreateProperty Value='$(B)|$(P)'>
      <Output TaskParameter='Value' PropertyName='Q' />
    </CreateProperty>
  </Target>
</Project>";
			var xml = XmlReader.Create (new StringReader (project_xml));
			var root = ProjectRootElement.Create (xml);
			root.FullPath = "ProjectInstanceTest.EvaluatePropertyWithQuotation.proj";
			var proj = new ProjectInstance (root);
			proj.Build ();
			var p = proj.GetProperty ("P");
			Assert.AreEqual ("xxx.txt", p.EvaluatedValue, "#1");
			var q = proj.GetProperty ("Q");
			Assert.AreEqual ("foobar|xxx.txt", q.EvaluatedValue, "#2");
		}
コード例 #12
0
ファイル: ResolvedImportTest.cs プロジェクト: nlhepler/mono
		public void EvaluateMSBuildThisFileProperty ()
		{
			string xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
  <PropertyGroup>
    <A>$(MSBuildThisFile)</A>
  </PropertyGroup>
  <Import Project='test_imported.proj' />
</Project>";
			string imported = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
  <PropertyGroup>
    <B>$(MSBuildThisFile)</B>
  </PropertyGroup>
</Project>";
			using (var ts = File.CreateText (temp_file_name))
				ts.Write (imported);
			try {
				var reader = XmlReader.Create (new StringReader (xml));
				var root = ProjectRootElement.Create (reader);
				var proj = new Project (root);
				var a = proj.GetProperty ("A");
				Assert.AreEqual (string.Empty, a.EvaluatedValue, "#1");
				var b = proj.GetProperty ("B");
				Assert.AreEqual (temp_file_name, b.EvaluatedValue, "#2");

				var pi  = new ProjectInstance (root);
				var ai = pi.GetProperty ("A");
				Assert.AreEqual (string.Empty, ai.EvaluatedValue, "#3");
				var bi = pi.GetProperty ("B");
				Assert.AreEqual (temp_file_name, bi.EvaluatedValue, "#4");
			} finally {
				File.Delete (temp_file_name);
			}
		}
コード例 #13
0
 public static ProjectPropertyInstance AssertPropertyExists(ProjectInstance projectInstance, string propertyName)
 {
     ProjectPropertyInstance propertyInstance = projectInstance.GetProperty(propertyName);
     Assert.IsNotNull(propertyInstance, "The expected property does not exist: {0}", propertyName);
     return propertyInstance;
 }