Auto Include Files In A C# Project

荒凉一梦 提交于 2019-12-24 01:18:00

问题


This may not really sound hard to do but it is currently killing me. Currently i have a Visual Studio 2008 C# Project that i use in conjunction with a DAL generator , its nothing fancy at all besides generating files that i can use in the project to access the database.

The problem i am having is that after the generator has run and the files are created they never show up in my project (new files , old existing files are fine). To add them i have to show hidden files (In visual studio) then include all of the files manually. So is there anyway to automatically include these files into my project.

Thanks in advance


回答1:


In VS2008:

1) Right click on your project node.

2) Select "Unload project".

3) Right click on the project node.

4) Select "Edit foo.csproj"

5) In the element add a element that includes your DAL files using wildcards like:

<Compile Include="DAL_*.cs" /> 

or

<Compile Include="DataAccessLayer\*.cs" /> 

6) File.Save

7) Right click on the project node.

8) Select "Reload project".

To learn more about this read up on MSBuild.




回答2:


I suppose the easiest way would be to write a tool to automatically modify the .csproj file, which is just XML, so that it includes your new items.




回答3:


I'd go one further than mquander and say generate the whole project file for your DAL. When it changes I think VS should prompt you to reload it.

The csproj is an msbuild file and isn't that hard to comprehend.



来源:https://stackoverflow.com/questions/510295/auto-include-files-in-a-c-sharp-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!