开发者

Adding Files to a Project Programmatically VS 2010

开发者 https://www.devze.com 2023-04-03 23:09 出处:网络
I have build a deployment .exe that minifies and combines JS and CSS files.Everything works great except that when I publish my website these files are not published.This is because these files are ad

I have build a deployment .exe that minifies and combines JS and CSS files. Everything works great except that when I publish my website these files are not published. This is because these files are added to the proper directories within my project but are开发者_开发技巧 not included in the project.

I know there is a option to include all files when publishing, but I don't want to do that. I simply want to be able to programmatically add these couple of JS and CSS files to the solution during the deployment process.


You can try adding a custom MSBuild target to your .csproj that will add the files dynamically to the project during the build process. They won't show up in the IDE, but I think that's what you want. The following target should add a test.css file that would be included in the publish process:

<Target Name="CustomContent" AfterTargets="ResolveReferences">
   <ItemGroup>
      <Content Include="Content\Styles\test.css"/>
   </ItemGroup>
</Target>

You would replace the contents of the Include attribute with the files you want to add to the deployment. You can also change the name of the target to whatever you want. It will need to go in the bottom of your.csproj file, just above the close of the Project element. I verified this in a MVC3 project, but it should also work in ASP.NET projects as well.


I ended up just writing the XML to my csproj file.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号