本文介绍了如何在此代码中添加页脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void WriteSingleMSBuildFile(List<ProjectItem> projectToWrite, string compilerOutputPath, string msBuildConfigPath)
        {
            foreach (var item in projectToWrite)
            {
                // Create an output file
                string msbuildFilename = string.Format("{0}.msbuild", Path.GetFileNameWithoutExtension(item.FullPath));

                string outputFile = Path.Combine(msBuildConfigPath, msbuildFilename);

                using (StreamWriter msbuildFile = new StreamWriter(outputFile))
                {
                    msbuildFile.WriteLine(GetMSBuildFileHeader());

                    // Add the Detail

                    // Add the Footer

                    msbuildFile.Close();
                }
            }
        }



[edit]删除喊话-OriginalGriff [/edit]



[edit]SHOUTING removed - OriginalGriff[/edit]

推荐答案

private void WriteSingleMSBuildFile(List<ProjectItem> projectToWrite, string compilerOutputPath, string msBuildConfigPath)
{
    // You know that projectToWrite is a List of ProjectItem instances
    // so there is really no reason to use var here
    foreach (ProjectItem item in projectToWrite)
    {
        // Create an output file
        string msbuildFilename = string.Format("{0}.msbuild", Path.GetFileNameWithoutExtension(item.FullPath));

        string outputFile = Path.Combine(msBuildConfigPath, msbuildFilename);

        using (StreamWriter msbuildFile = new StreamWriter(outputFile))
        {
            // This method isn't shown anywhere, but I think it should get item as its parameter
            // so it can output information about the ProjectItem into the build files header.
            msbuildFile.WriteLine(GetMSBuildFileHeader(item));

            // Add the Detail
            // Analogous to writing the header we invoke a method that will build the build-file details from
            // the ProjectItem item.
            msbuildFile.WriteLine(GetMSBuildFileDetails(item));

            // Add the Footer
            // Analogous to writing the details we invoke a method that will build the build-file footer from
            // the ProjectItem item.
            msbuildFile.WriteLine(GetMSBuildFileFooter(item));

            msbuildFile.Close();
        }
    }
}



现在您要做的就是编写三种方法GetMSBuildFileHeader(ProjectItem item)GetMSBuildFileDetail(ProjectItem item)GetMSBuildFileFooter(ProjectItem item).

问候,

—MRB



All you have to work out now is how to write the three methods GetMSBuildFileHeader(ProjectItem item), GetMSBuildFileDetail(ProjectItem item) and GetMSBuildFileFooter(ProjectItem item).

Regards,

—MRB


这篇关于如何在此代码中添加页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 07:59