c# - How to programmatically include a file in my project? -
background
i'm making helper application reformats code files , creates new code files, added other project, use new code right away, i'm having serious trouble adding new code file project automatically. way it's in c# , helper app winforms.
failed attempts
this question's answer has 2 ways of doing that, couldn't make of them work. first can't find microsoft.build assembly reference, , in other there not enough arguments command line.
question
how programmatically include file project without use of third-party applications?
basically, i'm looking equivalent of this:

...but done using code.
requirements
these features suppose solution should offer:
- select solution has project we're adding file to
- select project file added
- select directory within project
- and, of course, file we're adding
progress
with user @psubsee2003's able find microsoft.build.dll file in c:\windows\microsoft.net\framework\v4.0.30319 folder on computer , import changing project's target framework version 4 full profile, not default client profile.
and found how use additem method:
var p = new microsoft.build.evaluation.project(@"c:\projects\myproject.csproj"); p.additem("compile", @"c:\folder\file.cs"); p.save(); the file appear in project's root folder unless project had folder called folder, in case file placed there. file placed in deepest folder chain found in original file's path going towards root folder.
it worked adding projectfolder, , add folder programmatically this.
var p = new microsoft.build.evaluation.project(@"c:\projects\babdb\test\test.csproj"); p.additem("folder", @"c:\projects\babdb\test\test2"); p.additem("compile", @"c:\projects\babdb\test\test2\class1.cs"); p.save();
Comments
Post a Comment