是否有可能自动设置"复制到输出目录"创建Visual Studio 2010中的文件时? [英] Is it possible to automatically set "Copy to Output Directory" when creating files in Visual Studio 2010?

查看:402
本文介绍了是否有可能自动设置"复制到输出目录"创建Visual Studio 2010中的文件时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始LuaInterface玩弄获得Lua脚本在我的C#程序工作。为了便于从Visual Studio中创建Lua脚本,我安装了一个Lua语法高亮插件并创建了一个项目模板,这样我可以在项目文件,并选择新建用品 - > Lua的脚本通过右键单击新的脚本。这工作得很好。

I recently started playing around with LuaInterface to get Lua scripting working in my C# programs. In order to easily create Lua scripts from within Visual Studio, I installed a Lua syntax highlighting plugin and created an Item Template so that I could create new scripts by right clicking on the project file and selecting "New Item->Lua Script". This works quite well.

为了该程序找到脚本,需要将它们放置在生成位置的相同的目录(或子目录)。这正是我想要他们,但是为了做到这一点,我必须将复制到输出目录更改设置每个新文件创建。

In order for the program to find the scripts, they need to be placed in the same directory (or a subdirectory) of the build location. This is exactly where I want them, but in order to do this, I have to change the "Copy to Output Directory" setting for each new file I create.

有没有办法改变这个选项的默认设置?现在,它默认为不要复制。我只能找到<一个href=\"http://stackoverflow.com/questions/1849907/changing-the-default-copy-to-output-directory-setting-for-text-files\">one 要求基​​本相同的事情,但只要有唯一的答案另一个问题提出了一个生成后事件复制所有文件具有相同的扩展定义的位置。我真的不希望这样做,因为目标位置可能会改变或可加入更多的目标(并需要额外的事件?),我希望能够改变,设置在每个文件的基础上。

Is there a way to change the default setting of this option? Right now it defaults to "Do not copy". I could only find one other question asking essentially the same thing but the only answer provided there suggested a post-build event copying all files with the same extension to a defined location. I don't really want to do this since the target destination may change or more targets may be added (and would require additional events?) and I would like to be able to change that setting on a per-file basis.

这仅仅是一个方便的问题,因为我可以手动更改选项为每个文件,但已经能够在过程的其余部分自动完成,我希望我能和自动化这一个最后的细节。

This is just a convenience issue, as I can change that option manually for each file, but having been able to automate the rest of the process, I was hoping I could automate this one last detail as well.

推荐答案

您应该能够添加的添加 - 相对=nofollow> IWizard 参考模板,这将当您单击<大骨节病>确定​​的文件中运行窗口。您需要添加组件,然后键入到vstemplate文件。

You should be able to add an IWizard reference to the template, this will run when you click ok in the File -> Add window. You'll need to add the assembly and type to the vstemplate file.

实施<一个href=\"http://msdn.microsoft.com/en-us/library/vstudio/microsoft.visualstudio.templatewizard.iwizard.runfinished.aspx\"相对=nofollow> RunFinished 或可能的<一个href=\"http://msdn.microsoft.com/en-us/library/vstudio/microsoft.visualstudio.templatewizard.iwizard.projectitemfinishedgenerating.aspx\"相对=nofollow> ProjectItemFinishedGenerating 方法。然后,您可以使用Visual Studio中暴露出来的 EnvDTE 对象使用标准的Visual Studio扩展模型来进行处理解决方案中的任何项目。

Implement the RunFinished or possibly the ProjectItemFinishedGenerating method. You can then use the EnvDTE object exposed by Visual Studio to manipulate any item in the solution using the standard Visual Studio Extensibility model..

以下code SNIPPIT (从开源T4工具箱)展示了如何设置这个属性。

The following code snippit (from the open source T4 Toolbox) shows how to set this property.

    /// <summary>
    /// Sets the known properties for the <see cref="ProjectItem"/> to be added to solution.
    /// </summary>
    /// <param name="projectItem">
    /// A <see cref="ProjectItem"/> that represents the generated item in the solution.
    /// </param>        
    /// <param name="output">
    /// An <see cref="OutputFile"/> that holds metadata about the <see cref="ProjectItem"/> to be added to the solution.
    /// </param>
    private static void SetProjectItemProperties(ProjectItem projectItem, OutputFile output)
    {
        // Set "Build Action" property
        if (!string.IsNullOrEmpty(output.BuildAction))
        {
            ICollection<string> buildActions = GetAvailableBuildActions(projectItem);               
            if (!buildActions.Contains(output.BuildAction))
            {
                throw new TransformationException(
                    string.Format(CultureInfo.CurrentCulture, "Build Action {0} is not supported for {1}", output.BuildAction, projectItem.Name));
            }

            SetPropertyValue(projectItem, "ItemType", output.BuildAction);
        }

        // Set "Copy to Output Directory" property
        if (output.CopyToOutputDirectory != default(CopyToOutputDirectory))
        {
            SetPropertyValue(projectItem, "CopyToOutputDirectory", (int)output.CopyToOutputDirectory);
        }

        // Set "Custom Tool" property
        if (!string.IsNullOrEmpty(output.CustomTool))
        {
            SetPropertyValue(projectItem, "CustomTool", output.CustomTool);
        }

        // Set "Custom Tool Namespace" property
        if (!string.IsNullOrEmpty(output.CustomToolNamespace))
        {
            SetPropertyValue(projectItem, "CustomToolNamespace", output.CustomToolNamespace);
        }    
    }

这篇关于是否有可能自动设置&QUOT;复制到输出目录&QUOT;创建Visual Studio 2010中的文件时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆