C# 如何在VisualStudio中调试输出类型为类库的项目?

C# 如何在VisualStudio中调试输出类型为类库的项目?,c#,visual-studio,C#,Visual Studio,我遇到了一个需要在类库项目的方法中调试的问题?但我收到一个项目错误,上面说“输出类型为类库的项目不能直接启动”? 有办法解决这个问题吗?我的项目是一个用户控件 [XRDesigner("Rapattoni.ControlLibrary.CCMLThreePicGalleryTableDesigner," + "Rapattoni.ControlLibrary")] public class CCMLThreePicGalleryCtrl : XRTable {

我遇到了一个需要在类库项目的方法中调试的问题?但我收到一个项目错误,上面说“输出类型为类库的项目不能直接启动”? 有办法解决这个问题吗?我的项目是一个用户控件

 [XRDesigner("Rapattoni.ControlLibrary.CCMLThreePicGalleryTableDesigner," + "Rapattoni.ControlLibrary")]
    public class CCMLThreePicGalleryCtrl : XRTable
    {
        #region Variables
        const int cTableWidth = 825;
        #endregion

        #region Properties
        /// <summary>
        /// Get\Set  bindable variables
        /// </summary>

        [Bindable( true ), DesignerSerializationVisibility( DesignerSerializationVisibility.Hidden )]
        public string SerialPicUrlString
        {
            get
            {
                return String.Empty;
            }
            set
            {
                SetPictures( value );
            }
        }

        private int CellWidth
        {
            get;  
            set;
        }

        private int CellHeight
        {
            get;  
            set;
        }

        private int PicHeight
        {
            get;  
            set;
        }

        private int PicWidth  
        { 
            get; set; 
        }

        private int MaximumPictures
        {
            get; set;
        }
        #endregion Properties


        #region Events

        #endregion

        #region Public/Private Methods

        private void SetPictures( string urlString )
        {
            CellWidth = 275;
            CellHeight = 130;
            PicWidth = 175;
            PicHeight = 120;
            //CommentCellWidth = "150";
            MaximumPictures = 12;

            this.Rows.Clear();
            this.BeginInit();

            string[] urls = urlString.Split( ';' );

            XRPictureBox picBox;
            XRTableRow row;
            CCMLThreePicGalleryCell cell;  //, CommentCell;

            // Prepare first Row
            row = new XRTableRow();
            row.Height = CellHeight; 
            row.CanShrink = false;

            int picTotal = urls.Length;
            /*
            if (picTotal % 3 == 1)  // Don't have one picture in a row
                picTotal--;
             */
            if (picTotal > MaximumPictures)      // Max of 12 pictures shown
                picTotal = MaximumPictures;
            else if (picTotal == 1)
                picTotal = 0;

            // Keep track of which picture
            int picCount = 0;
            // Go through each picture and assign to a cell
            for (int i = 0; i < picTotal; i++)
            {
                if (urls[i] != "")
                {

                    if (picCount % 3 == 0 && picCount > 0 )   // Make a new row after every 3rd picture
                    {
                        // Create a new row for pictures
                        row = new XRTableRow();
                        row.Height = CellHeight;
                        row.CanShrink = false;
                    }


                    cell = new CCMLThreePicGalleryCell();
                    cell.Size = new Size(CellWidth, CellHeight);
                    cell.CanShrink = false;
                    cell.Padding = new PaddingInfo(0, 0, 5, 5);


                    //CommentCell = new ThreePicGalleryCell(); // Don't want Comments

                    string[] url_comment = urls[i].Split('|');
                    picBox = new XRPictureBox();
                    //picBox.HtmlItemCreated += new HtmlEventHandler(picBox_HtmlItemCreated);
                    picBox.Sizing = ImageSizeMode.ZoomImage;
                    url_comment[0] = url_comment[0].Trim();
                    picBox.ImageUrl = url_comment[0];
                    picBox.Size = new Size(PicWidth, PicHeight);

                    cell.Controls.Add(picBox);

                    row.Cells.Add(cell);

                    if (picCount % 3 == 0)   // Add Finalized row
                    {
                        this.Rows.Add(row); // Add current row

                    }
                picCount++;
                } 
            }
            // Fix for odd bug where final picture is out 
            // of alignment if it is 2nd in the last row 
            if (picCount % 3 == 2)
            {
                cell = new CCMLThreePicGalleryCell();
                cell.Size = new Size(CellWidth, CellHeight);
                row.Cells.Add(cell);
                this.Rows.Add(row);
            }
            else if (picCount % 3 == 1)  // When last row has 1 picture
            {
                this.Rows.Remove(row);
            }


            if (urlString.Equals(string.Empty))
                this.Rows.Clear();

            this.EndInit();

        }

        #endregion
    }
[XRDesigner(“Rapattoni.ControlLibrary.CCMLThreePicGalleryTableDesigner,“+”Rapattoni.ControlLibrary”)]
公共类CCMLThreePicGalleryCtrl:XRTable
{
#区域变量
const int cTableWidth=825;
#端区
#区域属性
/// 
///获取\设置可绑定变量
/// 
[可绑定(true)、DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
公共字符串SerialPicUrlString
{
得到
{
返回字符串。空;
}
设置
{
设置图片(值);
}
}
专用整数单元格宽度
{
得到;
设置
}
私人室内高度
{
得到;
设置
}
私人国际皮海酒店
{
得到;
设置
}
私有整数皮宽
{ 
获得;设置;
}
私有整数最大值
{
获得;设置;
}
#端域属性
#地区活动
#端区
#区域公共/私人方法
私有void SetPictures(字符串urlString)
{
细胞宽度=275;
单元高度=130;
皮宽=175;
皮高=120;
//CommentCellWidth=“150”;
最大图像数=12;
this.Rows.Clear();
this.BeginInit();
string[]url=urlString.Split(“;”);
XRPictureBox picBox;
XRTableRow行;
CCMLThreePicGalleryCell;/,CommentCell;
//准备第一排
行=新的XRTableRow();
行高=单元高度;
row.CanShrink=false;
int picTotal=url.Length;
/*
if(picTotal%3==1)//一行中没有一张图片
象形--;
*/
if(picTotal>MaximumPictures)//最多显示12张图片
picTotal=最大图片数;
else if(象形=1)
象形图=0;
//跟踪哪张图片
int picCount=0;
//浏览每张图片并分配给一个单元格
对于(int i=0;i0)//在每三张图片后新建一行
{
//为图片创建新行
行=新的XRTableRow();
行高=单元高度;
row.CanShrink=false;
}
cell=新的CCMLThreePicGalleryCell();
cell.Size=新的大小(CellWidth、CellHeight);
cell.CanShrink=false;
单元格填充=新填充信息(0,0,5,5);
//CommentCell=new ThreePicGalleryCell();//不需要注释
字符串[]url_comment=url[i]。拆分(“|”);
picBox=新的XRPictureBox();
//picBox.HtmlItemCreated+=新的HtmlEventHandler(picBox\u HtmlItemCreated);
picBox.Sizing=ImageSizeMode.ZoomImage;
url_comment[0]=url_comment[0].Trim();
picBox.ImageUrl=url_注释[0];
picBox.Size=新尺寸(PicWidth、PicHeight);
cell.Controls.Add(picBox);
行.单元格.添加(单元格);
if(picCount%3==0)//添加最终确定的行
{
this.Rows.Add(row);//添加当前行
}
picCount++;
} 
}
//修复了最终图片出现的奇怪错误
//如果它是最后一行中的第二个,则表示对齐
如果(picCount%3==2)
{
cell=新的CCMLThreePicGalleryCell();
cell.Size=新的大小(CellWidth、CellHeight);
行.单元格.添加(单元格);
this.Rows.Add(row);
}
else if(picCount%3==1)//当最后一行有1张图片时
{
this.Rows.Remove(row);
}
if(urlString.Equals(string.Empty))
this.Rows.Clear();
this.EndInit();
}
#端区
}

设置第二个小项目来使用库。

将Visual Studio调试器附加到二进制文件正在运行的进程。

通常我会创建一个单独的单元测试类库项目,然后在您最喜欢的单元测试运行程序中启动该项目,并以这种方式进行调试


或者,开始调试实际使用类库的任何应用程序,练习将命中您想要设置的任何断点的功能,然后从那里继续。

我同意Jon Skeet的观点。TDD(测试驱动开发)是面向服务或业务逻辑类的最佳方式


它允许您启动GUI的一小部分并对其进行测试,而无需加载整个应用程序

你为什么不写一个测试工具呢?也许是一个控制台应用程序。类库不是可执行的,因此无法直接启动以进行调试。调试器只能附加到正在运行的进程。Jon Skeets单元测试样式的项目是最好的选择。我不确定如何实现这一点。您有任何参考资料吗?调试菜单->附加到进程请将“DTT”更改为“TDD”