1

I am creating some classes by C# CodeDOM, in run time. then i include cs files that i created by CodeDOM in my project like this:

var p = new Microsoft.Build.Evaluation.Project(@"D:\imanSal\SmlpeApp\SmlpeApp\SmlpeApp.csproj");
p.AddItem("Compile", outputFileName + this.ClassName + ".cs");
p.Save();
p.Build();

Then im getting a File Modification detected warning because my project has been modified outside the environment, so I have to reload it. What must I do if I want to Reload my project programmatically in run time? what's the best solution for this?

1 Answer 1

1

You could include additional files to compile by specify them in the project file. For example, put dynamic creating file to Lib folder, then you can add this code to your project file (<Compile Include="Lib\*.cs" />), after that these files will be included during the build.

 <ItemGroup>
    <Compile Include="Class1.cs" />
    <Compile Include="Lib\*.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>

The file modification detected waring is the feature of Visual Studio, so there isn’t the way to load the project programmatically through MSBuild.

Sign up to request clarification or add additional context in comments.

7 Comments

thanks ...you pushed me forward but my main problem is still exist. ...can you give me any solution about re compiling project (when some changes were happen) in iis?
or any solution for update dlls ? or what ever way which can solve my problem ?
@ImanSalehi Your code is ok, just remove p.AddItem and p.Save.
i did ...and it worked...but i think my iis need to recycle the apppool(or some think like that) because the changes (which i did with code dom) will implement in project( dlls), only when the project stop and run again ...my problem is this
@ImanSalehi The application pool need to be recycled if the app has been compiled, there isn't the way to prevent it.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.