Click here to Skip to main content
15,921,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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]SHOUTING removed - OriginalGriff[/edit]
Posted
Updated 20-Oct-11 23:10pm
v2
Comments
OriginalGriff 21-Oct-11 5:10am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.

1 solution

Just to give you couple of ideas:

C#
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();
        }
    }
}


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
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900