Beispiel #1
0
        public void CommentsInPreprocessing()
        {
            Microsoft.Build.Construction.XmlDocumentWithLocation.ClearReadOnlyFlags_UnitTestsOnly();

            string input  = FileUtilities.GetTemporaryFile();
            string output = FileUtilities.GetTemporaryFile();

            string _initialLoadFilesWriteable = Environment.GetEnvironmentVariable("MSBUILDLOADALLFILESASWRITEABLE");

            try
            {
                Environment.SetEnvironmentVariable("MSBUILDLOADALLFILESASWRITEABLE", "1");

                string content = ObjectModelHelpers.CleanupFileContents(@"
<Project DefaultTargets='Build' ToolsVersion='msbuilddefaulttoolsversion' xmlns='msbuildnamespace'>
  <Import Project='$(MSBuildToolsPath)\Microsoft.CSharp.targets'/>
</Project>");
                File.WriteAllText(input, content);

#if FEATURE_GET_COMMANDLINE
                Assert.Equal(MSBuildApp.ExitType.Success, MSBuildApp.Execute(@"c:\bin\msbuild.exe """ + input +
                                                                             (NativeMethodsShared.IsUnixLike ? @""" -pp:""" : @""" /pp:""") + output + @""""));
#else
                Assert.Equal(
                    MSBuildApp.ExitType.Success,
                    MSBuildApp.Execute(
                        new[] { @"c:\bin\msbuild.exe", '"' + input + '"',
                                '"' + (NativeMethodsShared.IsUnixLike ? "-pp:" : "/pp:") + output + '"' }));
#endif

                bool foundDoNotModify = false;
                foreach (string line in File.ReadLines(output))
                {
                    if (line.Contains("<!---->")) // This is what it will look like if we're loading read/only
                    {
                        Assert.True(false);
                    }

                    if (line.Contains("DO NOT MODIFY")) // this is in a comment in our targets
                    {
                        foundDoNotModify = true;
                    }
                }

                Assert.True(foundDoNotModify);
            }
            finally
            {
                File.Delete(input);
                File.Delete(output);
                Environment.SetEnvironmentVariable("MSBUILDLOADALLFILESASWRITEABLE", _initialLoadFilesWriteable);
            }
        }
Beispiel #2
0
        public void CommentsInPreprocessing()
        {
            Microsoft.Build.Construction.XmlDocumentWithLocation.ClearReadOnlyFlags_UnitTestsOnly();

            string input  = FileUtilities.GetTemporaryFile();
            string output = FileUtilities.GetTemporaryFile();

            try
            {
                string content = ObjectModelHelpers.CleanupFileContents(@"
<Project DefaultTargets='Build' ToolsVersion='msbuilddefaulttoolsversion' xmlns='msbuildnamespace'>
  <Import Project='$(MSBuildToolsPath)\microsoft.csharp.targets'/>
</Project>");
                File.WriteAllText(input, content);

                Assert.Equal(MSBuildApp.ExitType.Success, MSBuildApp.Execute(@"c:\bin\msbuild.exe """ + input + @""" /pp:""" + output + @""""));

                bool foundDoNotModify = false;
                foreach (string line in File.ReadLines(output))
                {
                    if (line.Contains("<!---->")) // This is what it will look like if we're loading read/only
                    {
                        Assert.True(false);
                    }

                    if (line.Contains("DO NOT MODIFY")) // this is in a comment in our targets
                    {
                        foundDoNotModify = true;
                    }
                }

                Assert.Equal(true, foundDoNotModify);
            }
            finally
            {
                File.Delete(input);
                File.Delete(output);
            }
        }