最新消息:20210917 已从crifan.com换到crifan.org

【已解决】VS2010中双击C#的.cs文件,结果不是打开vs文件,却出现:To add components to your class, drag them from the Toolbox and use the Properties window to set their properties. To create methods and events for your class, click here to switch to code view + 【未解决】添加CookComputing.XmlRpc后,wlw就无法识当前项目的dll插件

C# crifan 4456浏览 0评论

【问题】

之前使用VS2010打开C#项目中的.cs文件,双击的话,都是默认打开对应的源码的,但是自从给openPost.cs中添加了和CookComputing.XmlRpc相关的代码后:

using System;
using System.Collections.Generic;
using System.Text;
//using CookComputing.XmlRpc;
using CookComputing.XmlRpc;

namespace OpenPostViaPermaLink
{
    //class openPost : XmlRpcClientProtocol
    ////class openPost
    //{
    //    public openPost()
    //    { 
    //    }

        //public struct Loginpar
        //{
        //    public string username;
        //    public string password;
        //}


        //[XmlRpcUrl("https://www.crifan.org/xmlrpc.php")]
        //public interface ixmlrpc : IXmlRpcProxy
        //{
        //    [XmlRpcMethod]
        //    string login(Loginpar par);
        //}

        //public void xmlRpcTest()
        //{
        //    XmlRpcProxyGen proxy = new XmlRpcProxyGen();
        //    Loginpar ppp;
        //    ppp.username= "jarlyyn";
        //    ppp.password= "your password";
        //    string re=(ppp);
        //    Console.WriteLine ("Login xml rpc test!");
        //    Console.WriteLine(re.ToString());
        //}

        //public struct Post_t
        //{
        //    public DateTime dateCreated;
        //    /// <summary>
        //    /// 文章正文内容
        //    /// </summary>
        //    public string description;
        //    public string title;
        //    public string postid;
        //    /// <summary>
        //    /// 分组名称即可
        //    /// </summary>
        //    public string[] categories;
        //    /// <summary>
        //    /// 1是可以评论,0是邪恶的关平
        //    /// </summary>
        //    public int mt_allow_comments;
        //    public int mt_allow_pings;
        //    public int mt_convert_breaks;
        //    public string mt_text_more;
        //    /// <summary>
        //    /// 文章摘要
        //    /// </summary>
        //    public string mt_excerpt;
        //    /// <summary>
        //    /// Tags,也叫标签
        //    /// </summary>
        //    public string mt_keywords;
        //    //public int[] mt_tb_ping_urls;
        //}


        [XmlRpcUrl("https://www.crifan.org/xmlrpc.php")]
        class CrifanMetaWeblog : XmlRpcClientProtocol
        {
            [XmlRpcMethod("metaWeblog.getPost")]
            //http://www.opencn.info/archives/219.html
            //metaWeblog.getPost
            //说明: 传回特定文章的信息。
            //参数: 字符串 postid, 字符串 username, 字符串 password
            //传回值: 成功的时候为包含字符串 userid, ISO.8601 dateCreated, 字符串 postid, 字符串 description, 字符串 title, 字符串 link, 字符串 permaLink, 字符串 mt_excerpt, 字符串 mt_text_more, 整数 mt_allow_comments, 整数 mt_allow_pings, 字符串 mt_convert_breaks, 字符串 mt_keywords 的结构;失败时为 fault

            //http://xmlrpc.scripting.com/metaWeblogApi.html
            //metaWeblog.newPost (blogid, username, password, struct, publish) returns string
            //metaWeblog.editPost (postid, username, password, struct, publish) returns true
            //metaWeblog.getPost (postid, username, password) returns struct
            //The blogid, username, password and publish params are as in the Blogger API. newPost returns a string representation of the post id, again as defined by the Blogger API. The struct is where the juice is.
            public Object getPost(string postid, string username, string password)
            {
                Object retInfo = null;
                retInfo = this.Invoke("getPost", new object[] { postid, username, password });
                return retInfo;
            }

            //metaWeblog.getRecentPosts (blogid, username, password, numberOfPosts) returns array of structs
            //Each struct represents a recent weblog post, containing the same information that a call to metaWeblog.getPost would return. 
            //If numberOfPosts is 1, you get the most recent post. If it's 2 you also get the second most recent post, as the second array element. If numberOfPosts is greater than the number of posts in the weblog you get all the posts in the weblog. 
            [XmlRpcMethod("metaWeblog.getRecentPosts")]
            public Object getRecentPosts(string blogid, string username, string password, string numberOfPosts)
            {
                return this.Invoke("getRecentPosts", new object[] { blogid, username, password, numberOfPosts });
            }
        }
          

//    }

    
}

结果双击这个openPost.cs后,就出现上述提示:

To add components to your class, drag them from the Toolbox and use the Properties window to set their properties. To create methods and events for your class, click here to switch to code view

图示:to add componets to your class

需要额外的右击后选择view code:

view code

然后才可以看到对应的源码。

同时,当前项目所生成的dll文件,也无法被WLW所识别了。(此项目是WLW的一个插件,之前生成的dll是可以被WLW所识别的)。

此处,想要搞清楚,为何:

1.双击cs文件,为何变成(类似于窗体的)design,而非直接打开源码了?

2.为何生成的dll无法被WLW所识别了。

估计解决了第一个问题,第二个问题自然就解决了。

【解决过程】

1.这里:How do I configure visual studio to use the code view as the default view for Webservices?,中的方案,其实是教你怎么改文件的打开方式,对此处VS2010的资源管理器中,说的不是一个问题.

2.看到:Deriving component from abstract base class breaks designer,中提到了一点是:

For components, the designer view gives you the actual component, or in case there is no visible interface, a message stating that you can switch to code view. This works even for abstract components.

所以看起来应该是,当前cs文件所引用的CookComputing.XmlRpc,是个component类型的,或者是abstract component类型的,所以才像窗体的cs文件一样,双击后,打开的design,而非source code.

但是此处生成的dll,却无法被wlw所识别了,不知道和解?

3.也看到了这里:C# : Add a visual component,贴图中出现了,VS2010新建中,就有Component Class,就是那个十字方格图标的Component类型的文件,所以,确定是这个原因了。但是还是无法解决wlw无法识别dll的问题。

4.另外,这里:Visual Studio 2008 and Classes Inheriting From System.Web.UI.WebControls.Style,解释的更清楚,就是component的问题导致不显示源码而显示design的。

5.另外,对于wlw插件不识别,经过一番折腾,发现了,另外建了一个C#项目,单独拷贝对应上述已经可以工作的代码过去,是可以避免成为component,而保持原形的cs源文件的。

但是最后编译出来的dll还是无法被wlw所识别。

6.经过折腾,发现,只要包含了:

using CookComputing.XmlRpc;

然后对应的去声明对应变量:

[XmlRpcUrl(https://www.crifan.org/xmlrpc.php)]

则wlw就无法识别此dll了,目前看来,好像是别的接口interface,会冲突掉原先的

using WindowsLive.Writer.Api;

[WriterPlugin(“710296af-da88-4fcc-90d1-247538f18c4e”, “Open Post via Permanent Link”,

Description = “An Windows Live Writer plugin, enable user to open an post from its permanent link. Created by Crifan.”,

HasEditableOptions = false,

Name = “OpenPostViaPermaLink”,

PublisherUrl = “https://www.crifan.org/”,

ImagePath = “icon.jpg”)]

[InsertableContentSource(“OpenPostViaPermaLink”)]

导致wlw无法识别自己的这个dll插件。

转载请注明:在路上 » 【已解决】VS2010中双击C#的.cs文件,结果不是打开vs文件,却出现:To add components to your class, drag them from the Toolbox and use the Properties window to set their properties. To create methods and events for your class, click here to switch to code view + 【未解决】添加CookComputing.XmlRpc后,wlw就无法识当前项目的dll插件

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
92 queries in 0.190 seconds, using 23.38MB memory