我在VS2010中有一个控制台应用程序(C#),在项目中我添加了一个文件夹(右键单击项目.. 添加->文件夹),我希望当我编译应用程序(调试或发布)时,文件夹会在调试或发布目录中创建(如果不存在)。
这是否可能?
该控制台应用程序是一个访问数据库并发送电子邮件的守护进程,其中模板分配在该文件夹中。
希望我能帮到你。谢谢!
这是否可能?
该控制台应用程序是一个访问数据库并发送电子邮件的守护进程,其中模板分配在该文件夹中。
希望我能帮到你。谢谢!
在构建期间,除了指定的输出文件夹外,VS没有“自动”创建文件夹的方式。但有两种相当简单的方法可以实现。
Use a post-build event, which you set up in the Build Events tab of your project's properties. This is basically a batch file that you run after the build completes, something like this:
IF NOT EXIST $(OutDir)MySubFolder MKDIR $(OutDir)MySubFolder
XCOPY /D $(ProjectDir)MySubFolder\*.tmpl $(OutDir)MySubFolder
Use MSBuild's AfterBuild event. This is my preferred method, mostly because it integrates better with our automated build process, but it's a little more involved:
Near the bottom is a commented-out pair of XML nodes. Uncomment the AfterBuild target and replace it with something like this:
<Target Name="AfterBuild">
<MakeDir Directory="$(OutDir)MySubFolder" Condition="!Exists('$(OutDir)MySubFolder')" />
<CreateItem Include="$(ProjectDir)MySubFolder\*.tmpl">
<Output TaskParameter="Include" ItemName="Templates" />
</CreateItem>
<Copy SourceFiles="@Templates" DestinationFolder="$(OutDir)MySubFolder" ContinueOnError="True" />
</Target>
Save the changes, close the .csproj file, then right-click and Reload the project.
<Target Name="AfterBuild">
<MakeDir Directories="$(OutDir)EmailTemplates" Condition="!Exists('$(OutDir)EmailTemplates')" />
<ItemGroup>
<Templates Include="$(ProjectDir)EmailTemplates\*.*" />
</ItemGroup>
<Copy SourceFiles="@(Templates)" DestinationFolder="$(OutDir)EmailTemplates" />
</Target>