visual-studio 在 VS2010 中使用发布工具时如何包含被忽略的文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3455409/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to include ignored files when using Publish tool in VS2010?
提问by jessegavin
I have a directory /media/fontsin my asp.net mvc project which contains fonts for my website. When I use the "Publish" tool in Visual Studio this folder is ignored even though it is included in my project. Other folders /media/imagesand /media/cssare included just fine.
/media/fonts我的 asp.net mvc 项目中有一个目录,其中包含我网站的字体。当我在 Visual Studio 中使用“发布”工具时,这个文件夹会被忽略,即使它包含在我的项目中。其他文件夹/media/images并/media/css包含在内就好了。
Is there any way to tell Visual Studio to not ignore this folder on publish?
有没有办法告诉 Visual Studio 在发布时不要忽略这个文件夹?
回答by jayhoonova
Select your font files and Change Build action as Content from Properties Window.
从属性窗口中选择您的字体文件和更改构建操作作为内容。
回答by Chris Moschini
You can fix this permanently by modifying the default Build Action for font file extensions (.eot, .ttf, etc)
您可以通过修改字体文件扩展名(.eot、.ttf 等)的默认构建操作来永久修复此问题
The link has been assassinated by the cruel march of time, so here's a copy/paste of its contents:
该链接已被残酷的时间流逝暗杀,因此这是其内容的复制/粘贴:
The default build action of a file type can be configured in the registry. However, instead of hacking the registry manually, we use a much better approach: pkgdef files (a good article about pkgdef files). In essence, pkdef are configuration files similar to .reg files that define registry keys and values that are automatically merged into the correct location in the real registry. If the pkgfile is removed, the changes are automatically undone. Thus, you can safely modify the registry without the danger of breaking anything – or at least, it's easy to undo the damage.
可以在注册表中配置文件类型的默认构建操作。然而,我们没有手动破解注册表,而是使用了更好的方法:pkgdef 文件(一篇关于 pkgdef 文件的好文章)。本质上,pkdef 是类似于 .reg 文件的配置文件,这些文件定义了自动合并到真实注册表中正确位置的注册表项和值。如果删除 pkgfile,更改将自动撤消。因此,您可以安全地修改注册表而不会破坏任何东西——或者至少,很容易消除损坏。
Finally, here's an example of how to change the default build action of a file type:
最后,这是一个如何更改文件类型的默认构建操作的示例:
[$RootKey$\Projects{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\FileExtensions.spark]
"DefaultBuildAction"="Content"
The Guid in the key refers to project type. In this case, {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}means “C# projects”. A rather comprehensive list of project type guids can be found here. Although it does not cover Visual Studio 2010 explicitly, the Guids apply to the current version as well. By the way, we can use C# as the project type here, because C# based MVC projects are in fact C# projects (and web application projects). For Visual Basic, you'd use {F184B08F-C81C-45F6-A57F-5ABD9991F28F}instead.
键中的 Guid 是指项目类型。在本例中,{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}表示“C# 项目”。可以在此处找到相当全面的项目类型指南列表。虽然它没有明确涵盖 Visual Studio 2010,但这些指南也适用于当前版本。顺便说一下,这里我们可以使用 C# 作为项目类型,因为基于 C# 的 MVC 项目实际上是 C# 项目(和 Web 应用程序项目)。对于 Visual Basic,您可以{F184B08F-C81C-45F6-A57F-5ABD9991F28F}改用。
$RootKey$is an abstraction of the real registry key that Visual Studio stores the configuration under:
$RootKey$是 Visual Studio 在下面存储配置的真实注册表项的抽象:
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio.0_Config
(Note: Do not try to manually edit anything under this key as it can be overwritten at any time by Visual Studio).
(注意:不要尝试手动编辑此键下的任何内容,因为 Visual Studio 可以随时覆盖它)。
The rest should be self explanatory: this option sets the default build action of .sparkfiles to “Content”, so those files are included in the publishing process.
其余的应该是不言自明的:此选项将.spark文件的默认构建操作设置为“内容”,因此这些文件包含在发布过程中。
All you need to do now is to put this piece of text into a file with the extension pkgdef, put it somewhere under
您现在需要做的就是将这段文本放入一个扩展名为 pkgdef 的文件中,将它放在下面的某个位置
%PROGRAMFILES(x86)%\Microsoft Visual Studio 10.0\Common7\IDE\Extensions
(on 64-bit systems) or
(在 64 位系统上)或
%PROGRAMFILES(x86)%\Microsoft Visual Studio 10.0\Common7\IDE\Extensions
(on 32-bit systems) and Visual Studio will load and apply the settings automatically the next time it starts. To undo the changes, simply remove the files.
(在 32 位系统上),Visual Studio 将在下次启动时自动加载和应用设置。要撤消更改,只需删除文件。
回答by Afshar Mohebbi
Visual Studio does publish font files. In a special case we renamed extensions from .ttfto .jpgand they got published.
Visual Studio 会发布字体文件。在特殊情况下,我们将扩展重命名为.ttfto.jpg并发布。

