如何以编程方式更改项目属性(内容处理器 XNA 4.0)?

How to change item properties programmatically (Content Processor XNA 4.0 )?

由于自定义内容处理器,我需要以编程方式更改模型的内容处理器或从 solution/project 更改 fbx 文件 属性(XNA Framework 内容管道-> 内容处理器)。 这都是因为我希望使用该程序的用户添加他的蒙皮模型并更改此 属性。 提前致谢,如果问题含糊或重复,我深表歉意。

更新

通过一些研究,我找到了一种访问项目的解决方案,但不幸的是,在尝试将项目项放入我的 solution/project 时出现错误。仍然可以访问项目属性(尚未尝试更改它们).

这是代码(类似于 MSDN 模板):

    static void Main(string[] args)
    {
        EnvDTE80.DTE2 dte;
        object obj = null;
        System.Type t = null;

        t = System.Type.GetTypeFromProgID("VisualStudio.DTE.11.0", true);

        obj = System.Activator.CreateInstance(t, true);

        dte = (EnvDTE80.DTE2)obj;

        string solutionFile = 
            "C:\Users\The Wizard Of Code\Documents\Visual Studio 2012\Projects\ConsoleApplication2\ConsoleApplication2.sln";

        MessageFilter.Register();
        //dte.MainWindow.Activate();

        /*Problem I think*/
        Solution2 soln = (Solution2)dte.Solution;
        soln.open(solutionFile);
        Console.WriteLine(soln.Item(1).ProjectItems.Item(1).Name);

        dte.Quit();
        MessageFilter.Revoke();

    }

错误信息: 消息过滤器指示应用程序正忙。 (HRESULT 异常:0x8001010A(RPC_E_SERVERCALL_RETRYLATER))

更新 2 消息过滤器 class: public class 消息过滤器:IOleMessageFilter { // // Class 包含 IOleMessageFilter // 线程错误处理函数。

    // Start the filter.
    public static void Register()
    {
        IOleMessageFilter newFilter = new MessageFilter();
        IOleMessageFilter oldFilter = null;
        CoRegisterMessageFilter(newFilter, out oldFilter);
    }

    // Done with the filter, close it.
    public static void Revoke()
    {
        IOleMessageFilter oldFilter = null;
        CoRegisterMessageFilter(null, out oldFilter);
    }

    //
    // IOleMessageFilter functions.
    // Handle incoming thread requests.
    int IOleMessageFilter.HandleInComingCall(int dwCallType,
      System.IntPtr hTaskCaller, int dwTickCount, System.IntPtr
      lpInterfaceInfo)
    {
        //Return the flag SERVERCALL_ISHANDLED.
        return 0;
    }

    // Thread call was rejected, so try again.
    int IOleMessageFilter.RetryRejectedCall(System.IntPtr
      hTaskCallee, int dwTickCount, int dwRejectType)
    {
        if (dwRejectType == 2)
        // flag = SERVERCALL_RETRYLATER.
        {
            // Retry the thread call immediately if return >=0 & 
            // <100.
            return 99;
        }
        // Too busy; cancel call.
        return -1;
    }

    int IOleMessageFilter.MessagePending(System.IntPtr hTaskCallee,
      int dwTickCount, int dwPendingType)
    {
        //Return the flag PENDINGMSG_WAITDEFPROCESS.
        return 2;
    }

    // Implement the IOleMessageFilter interface.
    [DllImport("Ole32.dll")]
    private static extern int
      CoRegisterMessageFilter(IOleMessageFilter newFilter, out 
      IOleMessageFilter oldFilter);
}

[ComImport(), Guid("00000016-0000-0000-C000-000000000046"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
interface IOleMessageFilter
{
    [PreserveSig]
    int HandleInComingCall(
        int dwCallType,
        IntPtr hTaskCaller,
        int dwTickCount,
        IntPtr lpInterfaceInfo);

    [PreserveSig]
    int RetryRejectedCall(
        IntPtr hTaskCallee,
        int dwTickCount,
        int dwRejectType);

    [PreserveSig]
    int MessagePending(
        IntPtr hTaskCallee,
        int dwTickCount,
        int dwPendingType);
}

抱歉加载了代码

更新 3

我设法访问了属性,但它们是文件属性,而不是我在某些项目或解决方案上右键单击该项目并在右下角获取该选项卡时获得的属性(我需要通过代码)。

[STA线程] 在 main 似乎解决问题之前 来源:http://msdn.developer-works.com/article/11266583/why+looping+through+projectitems+sometimes+causes+Exception+from+HRESULT%3A+0x8001010A+(RPC_E_SERVERCALL_RETRYLATER).....

更新 modelviewer.codeplex.com 有我需要的。