简体   繁体   English

Visual Studio:预构建将目录内容添加到项目

[英]Visual Studio: Pre-Build add contents of directory to project

I have the following setup: 我有以下设置:

  • Main Website - MVC 3 project, to be hosted on www.domain.com 主要网站-MVC 3项目,将托管在www.domain.com上

  • Intranet Web App - MVC 3 project, windows authentication, hosted on admin.domain.com, which is only accessible from within the local subnet. Intranet Web App-MVC 3项目,Windows身份验证,位于admin.domain.com上,只能从本地子网内访问。

  • CDN Website - A simple web app that merely serves images to both of the above. CDN网站-一个简单的Web应用程序,仅向上述两个网站提供图像。 It will be hosted (publically) on cdn.domain.com, when we go live. 当我们上线时,它将公开托管在cdn.domain.com上。 I have set up a local project to mock the CDN during development. 我已经建立了一个本地项目来在开发过程中模拟CDN。

I've written a business layer that allows users in the admin panel to upload images, which are then physically saved to the CDN path that's configured (currently on the local machine ie C:\\Code\\SolutionName\\CDNProject\\images). 我已经编写了一个业务层,允许用户在管理面板中上传图像,然后将其物理保存到已配置的CDN路径(当前在本地计算机上,即C:\\ Code \\ SolutionName \\ CDNProject \\ images)。 The main website then uses the same business layer to find and distribute the images via http://cdn.domain.com/images/ . 然后,主网站使用同一业务层通过http://cdn.domain.com/images/查找和分发图像。 http://cdn.domain.com is currently set to http://localhost:55555 , while we develop. http://cdn.domain.com当前设置为http://localhost:55555 ,而我们开发。

Whenever an image is created via the admin panel, it is physically created on disk. 每当通过管理面板创建映像时,都会在磁盘上物理创建该映像。 Each developer works on his own machine, we we want to be able to check these files in to TFS, for the time being. 每个开发人员都在自己的计算机上工作,我们希望能够暂时将这些文件检入TFS。 As you might have guessed, adding files to the file system does not automatically reference them in the project: 您可能已经猜到,将文件添加到文件系统并不会在项目中自动引用它们:

引用损坏

I thought there may be some way to reference these images as resources, or set a directory to a "content" directory of sorts... but I can't find anything. 我认为可能有某种方法可以将这些图像作为资源引用,或将目录设置为各种“内容”目录...但是我什么也找不到。

Some developers work remotely via VPN, and do not have access to the local network (only TFS), so a network path is not an acceptable solution. 一些开发人员通过VPN进行远程工作,并且无法访问本地网络(仅TFS),因此网络路径不是可接受的解决方案。

I thought I might be able to set a pre-build event up, to add all files in a directory to the project? 我以为我可以设置一个预构建事件,以将目录中的所有文件添加到项目中?

There is no very easy way to do that. 没有非常简单的方法可以做到这一点。 There are a few ways to think about: 有几种方法可以考虑:

1) Write VS adding which adds new files to project (via DTE - starting point ). 1)编写VS添加,它将新文件添加到项目中(通过DTE- 起点 )。 Find out how to automatically run this VS addin on Pre-Build step. 了解如何在“预构建”步骤中自动运行此VS加载项。 Install this addin to your developers machines. 将此插件安装到您的开发人员计算机上。

2) Extend your admin logic to automatically check-in the uploaded files to TFS via TFS API 2)扩展您的管理逻辑,以通过TFS API自动将上传的文件签入到TFS

3) try to apply more sofisticated techonologies like this one: T4 Tutorial: Integrating Generated Files in Visual Studio Projects 3)尝试应用更多类似的技术: T4教程:在Visual Studio项目中集成生成的文件

Hope that helps, 希望能有所帮助,

Visual Studio project files have an XML syntax. Visual Studio项目文件具有XML语法。 Project file properties can be modified in a simple text editor (files added/removed, etc.). 可以在简单的文本编辑器中修改项目文件的属性(添加/删除文件等)。

You can create a script to open your solution, and before actually opening the solution, you can scan that directory and "inject" the files (with the appropriate XML tags) in the project files. 您可以创建一个脚本来打开您的解决方案,并且在实际打开该解决方案之前,您可以扫描该目录并将文件(带有适当的XML标记)“注入”到项目文件中。

I don't think you can add this as a pre-build event because the project files are already loaded at that point, and you cannot modify them while they're used. 我认为您不能将其添加为预构建事件,因为此时项目文件已经加载,并且在使用它们时无法对其进行修改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Visual Studio 2010中预构建 - Pre-build in Visual Studio 2010 Visual Studio 2010中失败的预构建事件取消了构建 - failed pre-build event in visual studio 2010 cancels build Visual Studio 2010预构建事件,用于编译和部署解决方案 - Visual studio 2010 pre-build event to compile & deploy a solution 在 Visual Studio 2010 的预构建步骤中吞下错误 - Swallowing errors in pre-build steps in Visual Studio 2010 Visual Studio预构建事件:批处理文件退出代码为-1 - Visual Studio Pre-Build Event: Batch File Exit Code is -1 有没有办法从C#中的代码中修改Visual Studio 2008或2010项目预构建事件? - Is there a way to modify Visual Studio 2008 or 2010 project pre-build events from within your code in C#? 如何定义每次运行的Visual Studio 2010中的预生成/预编译步骤? - How to define a pre-build/pre-compile step in Visual Studio 2010, that runs every time? 在 Visual Studio 中为不同的生成配置使用不同的预生成事件 - Use different pre-build events for different build configurations in Visual Studio 在Visual Studio 2010后期构建和预构建事件中使用robocopy - Using robocopy with Visual Studio 2010 Post-build and Pre-build events 将Selenium作为Pre-Build事件运行时,Visual Studio 2010挂起 - Visual Studio 2010 hangs when running Selenium as Pre-Build event
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM