Exemplo n.º 1
0
        /// <summary>
        /// Converts a VS7/Everett project to Whidbey format, and compares the result with the expected
        /// contents to make sure they match.
        /// </summary>
        /// <param name="everettProjectContents"></param>
        /// <param name="whidbeyProjectContents"></param>
        /// <param name="additionalDummyFileToCreateInEverettProjectDirectory"></param>
        /// <param name="isMinorUpgrade"></param>
        /// <owner>RGoel</owner>
        internal static void ConvertAndCompare
            (
            string sourceProjectContents,
            string targetProjectContents,
            string additionalDummyFileToCreateInEverettProjectDirectory,
            bool isMinorUpgrade = false
            )
        {
            string sourceProjectFile = ObjectModelHelpers.CreateTempFileOnDiskNoFormat(sourceProjectContents);

            string dummyExtraFile = null;
            if (additionalDummyFileToCreateInEverettProjectDirectory != null)
            {
                dummyExtraFile = Path.Combine(Path.GetDirectoryName(sourceProjectFile), additionalDummyFileToCreateInEverettProjectDirectory);

                File.WriteAllText(dummyExtraFile, String.Empty);
            }

            try
            {
                ProjectFileConverter converter = new ProjectFileConverter();

                converter.OldProjectFile = sourceProjectFile;
                converter.IsUserFile = false;
                converter.IsMinorUpgrade = isMinorUpgrade;
                ProjectRootElement project = converter.ConvertInMemory();

                Helpers.CompareProjectXml(targetProjectContents, project.RawXml);
            }
            finally
            {
                File.Delete(sourceProjectFile);

                if (dummyExtraFile != null)
                {
                    File.Delete(dummyExtraFile);
                }
            }
        }
Exemplo n.º 2
0
        public void RemoveReferencesToEmptyResxPerBug248965()
        {
            string temp = Path.GetTempPath();
            string projFolder = temp + "\\projfolder";
            Directory.CreateDirectory(projFolder);
            string projectFile = projFolder + "\\project.proj";
            string resxFile1 = projFolder + "\\emptyresx1.resx";
            string resxFile2 = projFolder + "\\resx2.resx";
            string resxFile3 = projFolder + "\\emptyresx3.resx";
            string resxFile4 = projFolder + "\\resx4.resx";
            string resxFile5 = temp + "\\emptyresx5.resx";
            string resxFile6 = temp + "\\resx6.resx";
            string newProjectFile = "";

            #region projectContent
            string projectContent =
                @"<VisualStudioProject>
                    <CSHARP
                        ProjectType = ""Local""
                        ProductVersion = ""7.10.3077""
                        SchemaVersion = ""2.0""
                        ProjectGuid = ""{C8C8D42E-57AA-4911-BE3A-0C04D7497B6B}""
                    >
                        <Build>
                            <Settings
                                ApplicationIcon = ""App.ico""
                                AssemblyKeyContainerName = """"
                                AssemblyName = ""testEmptyResx""
                                AssemblyOriginatorKeyFile = """"
                                DefaultClientScript = ""JScript""
                                DefaultHTMLPageLayout = ""Grid""
                                DefaultTargetSchema = ""IE50""
                                DelaySign = ""false""
                                OutputType = ""WinExe""
                                PreBuildEvent = """"
                                PostBuildEvent = """"
                                RootNamespace = ""testEmptyResx""
                                RunPostBuildEvent = ""OnBuildSuccess""
                                StartupObject = """"
                            >
                                <Config
                                    Name = ""Debug""
                                    AllowUnsafeBlocks = ""false""
                                    BaseAddress = ""285212672""
                                    CheckForOverflowUnderflow = ""false""
                                    ConfigurationOverrideFile = """"
                                    DefineConstants = ""DEBUG;TRACE""
                                    DocumentationFile = """"
                                    DebugSymbols = ""true""
                                    FileAlignment = ""4096""
                                    IncrementalBuild = ""false""
                                    NoStdLib = ""false""
                                    NoWarn = """"
                                    Optimize = ""false""
                                    OutputPath = ""bin\Debug\""
                                    RegisterForComInterop = ""false""
                                    RemoveIntegerChecks = ""false""
                                    TreatWarningsAsErrors = ""false""
                                    WarningLevel = ""4""
                                />
                                <Config
                                    Name = ""Release""
                                    AllowUnsafeBlocks = ""false""
                                    BaseAddress = ""285212672""
                                    CheckForOverflowUnderflow = ""false""
                                    ConfigurationOverrideFile = """"
                                    DefineConstants = ""TRACE""
                                    DocumentationFile = """"
                                    DebugSymbols = ""false""
                                    FileAlignment = ""4096""
                                    IncrementalBuild = ""false""
                                    NoStdLib = ""false""
                                    NoWarn = """"
                                    Optimize = ""true""
                                    OutputPath = ""bin\Release\""
                                    RegisterForComInterop = ""false""
                                    RemoveIntegerChecks = ""false""
                                    TreatWarningsAsErrors = ""false""
                                    WarningLevel = ""4""
                                />
                            </Settings>
                            <References>
                                <Reference
                                    Name = ""System""
                                    AssemblyName = ""System""
                                    HintPath = ""..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.dll""
                                />
                                <Reference
                                    Name = ""System.Data""
                                    AssemblyName = ""System.Data""
                                    HintPath = ""..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Data.dll""
                                />
                                <Reference
                                    Name = ""System.Drawing""
                                    AssemblyName = ""System.Drawing""
                                    HintPath = ""..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Drawing.dll""
                                />
                                <Reference
                                    Name = ""System.Windows.Forms""
                                    AssemblyName = ""System.Windows.Forms""
                                    HintPath = ""..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Windows.Forms.dll""
                                />
                                <Reference
                                    Name = ""System.XML""
                                    AssemblyName = ""System.XML""
                                    HintPath = ""..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.XML.dll""
                                />
                            </References>
                        </Build>
                        <Files>
                            <Include>
                                <File
                                    RelPath = ""App.ico""
                                    BuildAction = ""Content""
                                />
                                <File
                                    RelPath = ""AssemblyInfo.cs""
                                    BuildAction = ""Compile""
                                />
                                <File
                                    RelPath = """ + Path.GetFileName(resxFile1) + @"""
                                    BuildAction = ""EmbeddedResource""
                                />
                                <File
                                    RelPath = """ + Path.GetFileNameWithoutExtension(resxFile2) + @".cs""
                                    SubType = ""Form""
                                    BuildAction = ""Compile""
                                />
                                <File
                                    RelPath = """ + Path.GetFileName(resxFile5) + @"""
                                    Link = ""..\" + Path.GetFileName(resxFile5) + @"""
                                    BuildAction = ""EmbeddedResource""
                                />
                                <File
                                    RelPath = """ + Path.GetFileName(resxFile6) + @"""
                                    Link = ""..\" + Path.GetFileName(resxFile6) + @"""
                                    BuildAction = ""EmbeddedResource""
                                />
                                <File
                                    RelPath = """ + Path.GetFileName(resxFile2) + @"""
                                    DependentUpon = """ + Path.GetFileNameWithoutExtension(resxFile2) + @".cs""
                                    BuildAction = ""EmbeddedResource""
                                />
                                <File
                                    RelPath = """ + Path.GetFileNameWithoutExtension(resxFile3) + @".cs""
                                    SubType = ""Form""
                                    BuildAction = ""Compile""
                                />
                                <File
                                    RelPath = """ + Path.GetFileName(resxFile3) + @"""
                                    DependentUpon = """ + Path.GetFileNameWithoutExtension(resxFile3) + @".cs""
                                    BuildAction = ""EmbeddedResource""
                                />
                                <File
                                    RelPath = """ + Path.GetFileName(resxFile4) + @"""
                                    BuildAction = ""EmbeddedResource""
                                />
                            </Include>
                        </Files>
                    </CSHARP>
                </VisualStudioProject>
                ";
            #endregion

            try
            {
                using (StreamWriter sw = new StreamWriter(projectFile))
                    sw.Write(projectContent);
                using (StreamWriter sw = new StreamWriter(resxFile1))
                    sw.Write("");
                using (StreamWriter sw = new StreamWriter(resxFile2))
                    sw.Write("not empty blah blah");
                using (StreamWriter sw = new StreamWriter(resxFile3))
                    sw.Write("");
                using (StreamWriter sw = new StreamWriter(resxFile4))
                    sw.Write("not empty blah blah");
                using (StreamWriter sw = new StreamWriter(resxFile5))
                    sw.Write("");
                using (StreamWriter sw = new StreamWriter(resxFile6))
                    sw.Write("not empty blah blah");

                ProjectFileConverter projectFileConverter = new ProjectFileConverter();
                projectFileConverter.OldProjectFile = projectFile;
                newProjectFile = projectFile + ".1";
                projectFileConverter.NewProjectFile = newProjectFile;
                projectFileConverter.IsUserFile = false;
                projectFileConverter.Convert(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath));

                string newContent;
                using (StreamReader sr = new StreamReader(newProjectFile))
                {
                    newContent = sr.ReadToEnd();
                }

                #region expectedContent
                string expectedContent = @"<ItemGroup>
    <Compile Include=""AssemblyInfo.cs"" />
    <Compile Include=""" + Path.GetFileNameWithoutExtension(resxFile3) + @".cs"">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include=""" + Path.GetFileNameWithoutExtension(resxFile2) + @".cs"">
      <SubType>Form</SubType>
    </Compile>
    <Content Include=""App.ico"" />
    <EmbeddedResource Include=""..\" + Path.GetFileName(resxFile6) + @""">
      <Link>resx6.resx</Link>
    </EmbeddedResource>
    <EmbeddedResource Include=""" + Path.GetFileName(resxFile2) + @""">
      <DependentUpon>" + Path.GetFileNameWithoutExtension(resxFile2) + @".cs</DependentUpon>
    </EmbeddedResource>
    <EmbeddedResource Include=""" + Path.GetFileName(resxFile4) + @""" />
  </ItemGroup>";
                #endregion

                Console.WriteLine("=actual=");
                Console.WriteLine(newContent);
                Console.WriteLine("==");
                Console.WriteLine("=expected=");
                Console.WriteLine(expectedContent);
                Console.WriteLine("==");

                Assert.AreNotEqual(-1, newContent.IndexOf(expectedContent));

                // shouldn't delete any
                Assert.IsTrue(File.Exists(resxFile1));
                Assert.IsTrue(File.Exists(resxFile2));
                Assert.IsTrue(File.Exists(resxFile3));
                Assert.IsTrue(File.Exists(resxFile4));
                Assert.IsTrue(File.Exists(resxFile5));
                Assert.IsTrue(File.Exists(resxFile6));

            }
            finally
            {
                if (File.Exists(projectFile)) File.Delete(projectFile);
                if (File.Exists(newProjectFile)) File.Delete(newProjectFile);
                if (File.Exists(resxFile1)) File.Delete(resxFile1);
                if (File.Exists(resxFile2)) File.Delete(resxFile2);
                if (File.Exists(resxFile3)) File.Delete(resxFile3);
                if (File.Exists(resxFile4)) File.Delete(resxFile4);
                if (File.Exists(resxFile5)) File.Delete(resxFile5);
                if (File.Exists(resxFile6)) File.Delete(resxFile6);
                if (Directory.Exists(projFolder)) Directory.Delete(projFolder);
            }
        }
Exemplo n.º 3
0
        public void ConvertP2PReferenceSearchForSolution()
        {
            ObjectModelHelpers.DeleteTempProjectDirectory();

            // **********************************************
            //                   EVERETT PROJECT
            // **********************************************
            string everettProjectFileRelativePath = @"Project\WindowsApplication1.csproj";
            ObjectModelHelpers.CreateFileInTempProjectDirectory(everettProjectFileRelativePath, @"

                <VisualStudioProject>
                    <CSHARP
                        ProjectType = `Local`
                        SchemaVersion = `2.0`
                        ProjectGuid = `{77E21864-797C-4220-974E-530BB832801B}`
                    >
                        <Build>
                            <Settings
                                ApplicationIcon = `App.ico`
                            >
                                <Config
                                    Name = `Debug`
                                    OutputPath = `bin\Debug\`
                                />
                                <Config
                                    Name = `Release`
                                    OutputPath = `bin\Release\`
                                />
                            </Settings>
                            <References>
                                <Reference
                                    Name = `System`
                                    AssemblyName = `System`
                                    HintPath = `..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.dll`
                                />
                                <Reference
                                    Name = `System.XML`
                                    AssemblyName = `System.XML`
                                    HintPath = `..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.XML.dll`
                                />
                                <Reference
                                    Name = `ClassLibrary1`
                                    Project = `{F532DD6D-9E5C-4FE8-BE84-96F37D47F45A}`
                                    Package = `{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}`
                                />
                            </References>
                        </Build>
                        <Files>
                            <Include>
                                <File
                                    RelPath = `Form1.cs`
                                    SubType = `Form`
                                    BuildAction = `Compile`
                                />
                                <File
                                    RelPath = `Form1.resx`
                                    DependentUpon = `Form1.cs`
                                    BuildAction = `EmbeddedResource`
                                />
                            </Include>
                        </Files>
                    </CSHARP>
                </VisualStudioProject>
                ");

            string resxFile = "Project\\Form1.resx";
            ObjectModelHelpers.CreateFileInTempProjectDirectory(resxFile, String.Empty);

            // **********************************************
            //                   EVERETT SOLUTION
            // **********************************************
            ObjectModelHelpers.CreateFileInTempProjectDirectory(@"WindowsApplication1.sln", 

                @"Microsoft Visual Studio Solution File, Format Version 8.00
                Project(`{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}`) = `WindowsApplication1`, `Project\WindowsApplication1.csproj`, `{77E21864-797C-4220-974E-530BB832801B}`
	                ProjectSection(ProjectDependencies) = postProject
	                EndProjectSection
                EndProject
                Project(`{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}`) = `ClassLibrary1`, `ClassLibrary1\ClassLibrary1.csproj`, `{F532DD6D-9E5C-4FE8-BE84-96F37D47F45A}`
	                ProjectSection(ProjectDependencies) = postProject
	                EndProjectSection
                EndProject
                Global
	                GlobalSection(SolutionConfiguration) = preSolution
		                Debug = Debug
		                Release = Release
	                EndGlobalSection
	                GlobalSection(ProjectConfiguration) = postSolution
		                {77E21864-797C-4220-974E-530BB832801B}.Debug.ActiveCfg = Debug|.NET
		                {77E21864-797C-4220-974E-530BB832801B}.Debug.Build.0 = Debug|.NET
		                {77E21864-797C-4220-974E-530BB832801B}.Release.ActiveCfg = Release|.NET
		                {77E21864-797C-4220-974E-530BB832801B}.Release.Build.0 = Release|.NET
		                {F532DD6D-9E5C-4FE8-BE84-96F37D47F45A}.Debug.ActiveCfg = Debug|.NET
		                {F532DD6D-9E5C-4FE8-BE84-96F37D47F45A}.Debug.Build.0 = Debug|.NET
		                {F532DD6D-9E5C-4FE8-BE84-96F37D47F45A}.Release.ActiveCfg = Release|.NET
		                {F532DD6D-9E5C-4FE8-BE84-96F37D47F45A}.Release.Build.0 = Release|.NET
	                EndGlobalSection
	                GlobalSection(ExtensibilityGlobals) = postSolution
	                EndGlobalSection
	                GlobalSection(ExtensibilityAddIns) = postSolution
	                EndGlobalSection
                EndGlobal
                ");

            // **********************************************
            //                   RANDOM OTHER SOLUTION
            // **********************************************
            ObjectModelHelpers.CreateFileInTempProjectDirectory(@"Project\Random.sln", 

                @"Microsoft Visual Studio Solution File, Format Version 8.00
                Project(`{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}`) = `ClassLibrary2`, `ClassLibrary2\ClassLibrary2.csproj`, `{11111111-9E5C-4FE8-BE84-96F37D47F45A}`
	                ProjectSection(ProjectDependencies) = postProject
	                EndProjectSection
                EndProject
                Global
	                GlobalSection(SolutionConfiguration) = preSolution
		                Debug = Debug
		                Release = Release
	                EndGlobalSection
	                GlobalSection(ProjectConfiguration) = postSolution
		                {11111111-9E5C-4FE8-BE84-96F37D47F45A}.Debug.ActiveCfg = Debug|.NET
		                {11111111-9E5C-4FE8-BE84-96F37D47F45A}.Debug.Build.0 = Debug|.NET
		                {11111111-9E5C-4FE8-BE84-96F37D47F45A}.Release.ActiveCfg = Release|.NET
		                {11111111-9E5C-4FE8-BE84-96F37D47F45A}.Release.Build.0 = Release|.NET
	                EndGlobalSection
	                GlobalSection(ExtensibilityGlobals) = postSolution
	                EndGlobalSection
	                GlobalSection(ExtensibilityAddIns) = postSolution
	                EndGlobalSection
                EndGlobal
                ");

            // **********************************************
            //                   WHIDBEY PROJECT
            // **********************************************
            string whidbeyProjectContents = @"

                <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace` DefaultTargets=`Build`>
                    <PropertyGroup>
                        <ProjectType>Local</ProjectType>
                        <SchemaVersion>2.0</SchemaVersion>
                        <ProjectGuid>{77E21864-797C-4220-974E-530BB832801B}</ProjectGuid>
                        <Configuration Condition=` '$(Configuration)' == '' `>Debug</Configuration>
                        <Platform Condition=` '$(Platform)' == '' `>AnyCPU</Platform>
                        <ApplicationIcon>App.ico</ApplicationIcon>
                        <FileUpgradeFlags>20</FileUpgradeFlags>
                    </PropertyGroup>
                    <PropertyGroup Condition=` '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' `>
                        <OutputPath>bin\Debug\</OutputPath>
                        <ErrorReport>prompt</ErrorReport>
                    </PropertyGroup>
                    <PropertyGroup Condition=` '$(Configuration)|$(Platform)' == 'Release|AnyCPU' `>
                        <OutputPath>bin\Release\</OutputPath>
                        <ErrorReport>prompt</ErrorReport>
                    </PropertyGroup>
                    <ItemGroup>
                        <ProjectReference Include=`..\ClassLibrary1\ClassLibrary1.csproj`>
                        <Name>ClassLibrary1</Name>
                        <Project>{F532DD6D-9E5C-4FE8-BE84-96F37D47F45A}</Project>
                        <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
                        </ProjectReference>
                        <Reference Include=`System`>
                        <Name>System</Name>
                        </Reference>
                        <Reference Include=`System.XML`>
                        <Name>System.XML</Name>
                        </Reference>
                    </ItemGroup>
                    <ItemGroup>
                        <Compile Include=`Form1.cs`>
                        <SubType>Form</SubType>
                        </Compile>
                    </ItemGroup>
                    <Import Project=`$(MSBuildToolsPath)\Microsoft.CSharp.targets` />
                    <PropertyGroup>
                        <PreBuildEvent />
                        <PostBuildEvent />
                    </PropertyGroup>
                </Project>
                ";

            ProjectFileConverter converter = new ProjectFileConverter();
            converter.OldProjectFile = Path.Combine(ObjectModelHelpers.TempProjectDir, everettProjectFileRelativePath);
            converter.IsUserFile = false;
            ProjectRootElement project = converter.ConvertInMemory();

            Helpers.CompareProjectXml(whidbeyProjectContents, project.RawXml);
        }