.csproj File - programmatically add / remove files

I wrote a C # code generator to generate entities and related class files in our Ling-To-SQL application. The code generator needs to add / remove files in TFS, as well as add / remove them from the .csproj file so that they are included or excluded in the respective projects.

I found out the interaction of TFS, but I was curious how to add / remove files from .csproj files programmatically or in a standard way. Does anyone have any experience?

Thanks - Randy

+5
source share
5 answers

- Visual Studio. Visual Studio (VBA). MSDN .

, . , Visual Studio, , .

+1

.csproj - XML, XSD. XML , .

XSD, : (XSD) .csproj?

+5

XML. DOM .

+1
source

I saw code generators that do not modify the project. A project always knows about the generated files, but the actual files are not included.

0
source

You create a sample file and then reference it, you can edit the XML file case ".aspx": {

                if ((File.ReadAllText((GlobalVariables.sDestinationPath).Trim() + "" + GlobalVariables.sProjName + "\\" + GlobalVariables.sProjName + projExtention).Contains("<Content Include=\"" + fileName1 + "\" />")) == false)
                    {
                        fileReader = File.ReadAllText(GlobalVariables.sDestinationPath + "" + GlobalVariables.sProjName + "\\" + GlobalVariables.sProjName + projExtention + "").Replace("<Content Include=\"Web.config\" />", "<Content Include=\"Web.config\" />" + "\n" + "    <Content Include=\"" + fileName1 + "\" />");
                        File.WriteAllText(GlobalVariables.sDestinationPath.Trim() + "" + GlobalVariables.sProjName + "\\" + GlobalVariables.sProjName + projExtention + "", fileReader);

                        fileReader = File.ReadAllText(GlobalVariables.sDestinationPath.Trim() + "" + GlobalVariables.sProjName + "\\" + GlobalVariables.sProjName + projExtention + "").Replace("<Compile Include=\"" + pathfol + "\" />", "<Compile Include=\"" + pathfol + "\" />" + "\n" + "    <Compile Include=\"" + fileName1 + ".vb\" > " + "\n" + "     <DependentUpon>" + fileName1 + "</DependentUpon>" + "\n" + "     <SubType>ASPXCodeBehind</SubType>" + "\n" + "    </Compile>" + "\n" + "    <Compile Include=\"" + fileName1 + ".designer.vb\">" + "\n" + "     <DependentUpon>" + fileName1 + "</DependentUpon>" + "\n" + " </Compile> ");
                        File.WriteAllText(GlobalVariables.sDestinationPath.Trim() + "" + GlobalVariables.sProjName + "\\" + GlobalVariables.sProjName + projExtention + "", fileReader);
                    }
0
source

All Articles