解决NuGet程序包更新安装失败的错误

管理NuGet程序包 中更新程序包,出现:

Failed to initialize the PowerShell host. If your PowerShell execution policy setting is set to AllSigned, open the Package Manager Console to initialize the host first

1. Step

Open Windows PowerShell, run as Administrator

2. Step

Setting an execution policy to RemoteSigned or Unrestricted should work. It must be changed under an administrator mode via a PowerShell console. Be aware that changes will be applied according to the bit version of the PowerShell console, so 32bit or 64 bit. So if you want to install a package in Visual Studio (32 bit version) which requires a specific policy you should change settings of the policy via PowerShell (x86).

The command in PowerShell (as administrator) to set the policy to unrestricted (as noted by @Gabriel in the comments) is:

start-job { Set-ExecutionPolicy Unrestricted } -RunAs32 | wait-job | Receive-Job

OR

NuGet is using the 32 bit console, so it wont be affected by changes to the 64 bit console. Run the following script to make sure you are configuring the 32 bit console.

start-job { Set-ExecutionPolicy RemoteSigned } -RunAs32 | wait-job | Receive-Job

3. Step

Restart Visual Studio

————————————————————-

如果所有的政策是正确的,但安装包时,仍有错误

无法初始化PowerShell主机。如果你的PowerShell执行策略设置为使用AllSigned,打开包管理器控制台首先初始化主机。

解决方案卸载  NuGet包管理器 插件,并重新安装它。

浏览器中自动补全的一处错误:ftp.so

几年来这个问题就一直存在。从注册ftp.so起发现的。

在Windows下,浏览器地址栏中输入不加HTTP协议的网址:“ftp.so”,回车后,浏览器总会把它自动修改为 “ftp://ftp.so/”。

在IE,Chrome,Opera,Edge,Firefox中,都测试,结果都是一样的。

先后给 Google Chrome,微软,Mozilla 等报告过问题,但从没收到过回应。

感觉所有浏览器的自动修正方法都是相同的,所以这也许是个某组织的问题比如:W3C.org。


更新备注:Chrome 2018年已经修正

农转公/公转农 System.Globalization.ChineseLunisolarCalendar 农历转公历/公历转农历

项目中有一个生日短信提醒功能,需要每年提醒。选农历, 每年提醒, 第二年的公历是不一样的,所以每一年的都需要自己计算。

设计的要求 ,他们说因为年纪大的人是只记得农历的。。。

网上资料不少,公历转农历现成的一堆。都是用微软的System.Globalization.ChineseLunisolarCalendar类写的,
但是农历转公历的很少,也有,但都是只提到方法的调用,比如下面:
 
正确的应该是1982-10-12 。由于 并没有详细说到关键的闰月计算, 所以起初很困惑,以为计算不准确。

检查全年的月份,发现有因为有闰月的情况,有润月则应该从该闰月起月份自动加一, 如1982年润四月,或则闰五月为6月,后面的月加一处理。
方便理解自己做个对照图:

正确的方法是,要先计算当年农历生日之前的月份有没有闰月,

有了就 直接构造农历日期对象是就把农历的月+1 为9月:

只要明白闰月这一点,其实就很简单了!

///////////
//公历转农历
///////////
            DateTime date = Convert.ToDateTime(textBox1.Text);	//格式:2000-1-1
            ChineseLunisolarCalendar cc = new ChineseLunisolarCalendar();

            if (date > cc.MaxSupportedDateTime || date < cc.MinSupportedDateTime)  
                MessageBox.Show("参数日期时间不在支持的范围内,支持范围:"+cc.MinSupportedDateTime.ToShortDateString()+"到"+cc.MaxSupportedDateTime.ToShortDateString());
            
            int year = cc.GetYear(date);
            int month = cc.GetMonth(date);
            int dayOfMonth = cc.GetDayOfMonth(date);
            int leapMonth = cc.GetLeapMonth(year);
            bool isLeapMonth = cc.IsLeapMonth(year, month);
            bool isLeapYear = cc.IsLeapYear(year);

            if (isLeapMonth || isLeapYear && month >= leapMonth)
                month -= 1;

            textBox2.Text = string.Concat(year, "-", month, "-", dayOfMonth);
///////////
//农历转公历
///////////

	    ChineseLunisolarCalendar cc = new ChineseLunisolarCalendar();
            DateTime date = Convert.ToDateTime(textBox2.Text);	//格式:2000-1-1
            int MonthsInYear = cc.GetMonthsInYear(date.Year);
            int LeapMonth = cc.GetLeapMonth(date.Year, 1);
            bool isLeapMonth = cc.IsLeapMonth(date.Year, date.Month);
            bool isLeapYear = cc.IsLeapYear(date.Year);

            if (isLeapMonth)
                date = cc.ToDateTime(date.Year, date.Month - 1, date.Day, 0, 0, 0, 0);
            else if(date.Month > LeapMonth)
                date = cc.ToDateTime(date.Year, date.Month + 1, date.Day, 0, 0, 0, 0);
            else
                date = cc.ToDateTime(date.Year, date.Month, date.Day, 0, 0, 0, 0);
            
            textBox1.Text = date.ToString("yyyy-MM-dd");

这是一个WinForm做的的实例Demo: WindowsFormsApplication1

找回 Windows Server 2012 中的磁盘清理功能

公司在阿里云的新服务器,系统C盘只有40G,装了一堆程序,配置好环境,只剩下大约3个G了,看着标红的C盘容量条,很不惬意,确定要清理一下。

习惯性手工清理 + CCleaner 清理,完了没有大多少。却发现Server 2012怎么没有“磁盘清理”这个功能按钮呢?

于是搜索引擎。。。

结果是,要在“服务器管理器”中打开勾选这个功能:

安装以后在磁盘属性页就可以找到“磁盘清理”的选项了!

Windows update 更新错误 80240016

方法/步骤

  1. 1

    方法一(推荐):开始菜单 ,在开始搜索框中  输入“疑难解答

    弹出疑难解答菜单 ,在系统和安全性一栏中  单击“使用Windows Update 解决问题”  单击下一步,系统会自动修复windows update的错误 (以下步骤等同方法二)

    windows update自动更新失败,如何快速修复
    windows update自动更新失败,如何快速修复
    windows update自动更新失败,如何快速修复
  2. 2

     方法二:

    开始菜单 ,单击“控制面板”

    在“控制面板”中,单击查看方式,选择“大图标”(或者“小图标”)

    向下翻,找到“疑难解答

    在系统和安全性一栏中  单击“使用Windows Update 解决问题” 单击下一步,系统会自动修复windows update的错误

  3. 3

     特别补充步骤,控制面板 打开网络和Internet ,Internet选项,“连接”选项卡  单击局域网设置按钮,去掉“自动检测设置”前的√, 保证这三个勾没有选中

    这样可以大大提高windows update的成功率(尤其是装好MSDN原版系统后 ,首次更新时可修复代理)

    windows update自动更新失败,如何快速修复
    windows update自动更新失败,如何快速修复
  4. 4

     重新启动电脑,一般情况下windows update就恢复正常了

    windows update自动更新失败,如何快速修复

    【END】

MS SQL SERVER 数据字典 生成SQL

在库内查询,可用于生成如下字段结构:

[表], [字段], [数据类型], [允许为空], [主键], [外键], [引用表], [说明描述]

SELECT TOP (100) PERCENT a.name AS 表, b.name AS 字段, c.name AS 数据类型, CASE WHEN b.isnullable = 0 THEN '-' WHEN b.isnullable = 1 THEN '是' END AS 允许为空,
CASE WHEN d .name IS NULL THEN '-' WHEN d .name IS NOT NULL THEN '是' END AS 主键, CASE WHEN e.parent_object_id IS NULL THEN 0 ELSE 1 END AS 外键,
CASE WHEN e.parent_object_id IS NULL THEN '-' ELSE g.name END AS 引用表, CASE WHEN h.value IS NULL THEN '-' ELSE h.value END AS 说明描述,
i.text AS 默认值
FROM sys.sysobjects AS a INNER JOIN
sys.syscolumns AS b ON a.id = b.id INNER JOIN
sys.systypes AS c ON b.xtype = c.xtype LEFT OUTER JOIN
(SELECT so.id, sc.colid, sc.name
FROM sys.syscolumns AS sc INNER JOIN
sys.sysobjects AS so ON so.id = sc.id INNER JOIN
sys.sysindexkeys AS si ON so.id = si.id AND sc.colid = si.colid
WHERE (si.indid = 1)) AS d ON a.id = d.id AND b.colid = d.colid LEFT OUTER JOIN
sys.foreign_key_columns AS e ON a.id = e.parent_object_id AND b.colid = e.parent_column_id LEFT OUTER JOIN
sys.objects AS g ON e.referenced_object_id = g.object_id LEFT OUTER JOIN
sys.extended_properties AS h ON a.id = h.major_id AND b.colid = h.minor_id LEFT OUTER JOIN
sys.syscomments AS i ON b.cdefault = i.id
WHERE (a.type = 'U') AND (c.name <> 'sysname')
ORDER BY 表, 字段

还有一个查全库表字段的,参见另一篇 《通过(sys.sysobjects)对象表,查询全库表的基础信息Sql Server 查询全库表信息

Team Foundation Server(TFS) 源代码管理服务器 更换IP地址或端口

源码管理服务器 Team Foundation Server(TFS) 的ip地址发生改变后, 解决方案连不上了.

解决方法是:

  • 1  打开”团队” -> “连接到 Team Foundation Server”, 移除原服务器地址

20140804104552

  • 2  编辑 项目解决方案.sln文件, 修改里面的 “SccTeamFoundationServer” 后面的TFS地址为新地址

  20140804105319

  • 3  打开 “C:\Users\Administrator\AppData\Local\Microsoft\Team Foundation\3.0\Cache”  版本不同, 文件夹可能是4.0.

修改 LocationServerMap.xml 文件, 删除其中的 “location” = 原地址的条目.

 20140804104744

  • 4  重新打来项目连接到TFS

 20140804104621

修改启动 Windows 服务时允许花费的时间

今天安装 Team Foundation Server。

20140725163301

在安装结果信息中有点以为的收获:
信息

启动 Windows 服务时允许花费的时间已从 30 秒增加为 600 秒。这会影响此服务器上的所有 Windows 服务。(注册表值设置是 HKLM\SYSTEM\CurrentControlSet\Control\!ServicesPipeTimeout。)

通过设置此注册表键值,调整加载服务所允许使用的时间。

SuperHidden.vbs , 右键 添加\卸载 “显示\隐藏 系统文件”

一段VB脚本,将“显示隐藏系统文件”加入到右键,如图。

20140725101903

Dim WSHShell
Set WSHShell = WScript.CreateObject("WScript.Shell")
WSHShell.RegWrite "HKCR\CLSID\{00000000-0000-0000-0000-000000000012}\Instance\InitPropertyBag\CLSID", "{13709620-C279-11CE-A49E-444553540000}", "REG_SZ"
WSHShell.RegWrite "HKCR\CLSID\{00000000-0000-0000-0000-000000000012}\Instance\InitPropertyBag\method", "ShellExecute", "REG_SZ"
if WSHShell.RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\HideFileExt") = 0 then
WSHShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\ShowSuperHidden", "0", "REG_DWORD"
WSHShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Hidden", "2", "REG_DWORD"
WSHShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\HideFileExt", "1", "REG_DWORD"
WSHShell.RegWrite "HKCR\CLSID\{00000000-0000-0000-0000-000000000012}\Instance\InitPropertyBag\command", "显示扩展名及文件", "REG_SZ"
WSHShell.SendKeys "{F5}+{F10}e"
else
WSHShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\ShowSuperHidden", "1", "REG_DWORD"
WSHShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Hidden", "1", "REG_DWORD"
WSHShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\HideFileExt", "0", "REG_DWORD"
WSHShell.RegWrite "HKCR\CLSID\{00000000-0000-0000-0000-000000000012}\Instance\InitPropertyBag\command", "隐藏扩展名及文件", "REG_SZ"
WSHShell.SendKeys "{F5}+{F10}e"
end if
Set WSHShell = Nothing
WScript.Quit(0)

查询获取表中, 字段,数据类型的sql

存档一个今天用到的sql,  可以用来查询表中, 字段, 数据类型的sql.

SELECT OBJECT_NAME(c.id) AS 表名, c.name AS 字段名, t.name AS 数据类型, 
      c.prec AS 长度
FROM syscolumns c INNER JOIN
      systypes t ON c.xusertype = t.xusertype
WHERE (objectproperty(c.id, 'IsUserTable') = 1) AND 
      (c.id = OBJECT_ID('你的表名'))

 

如果要查视图的话, 要修改一下where条件,  把where的objectproperty放到上面增加一个case判断,  AS 出类型

SELECT     CASE WHEN (OBJECTPROPERTY(c.id, 'IsUserTable') = 1) THEN 'Table' WHEN (OBJECTPROPERTY(c.id, 'IsView') = 1) THEN 'View' END AS 类型, OBJECT_NAME(c.id) 
                      AS 表名, c.name AS 字段名, t.name AS 数据类型, c.prec AS 长度
FROM         sys.syscolumns AS c INNER JOIN
                      sys.systypes AS t ON c.xusertype = t.xusertype
WHERE     (c.id = OBJECT_ID('View_1'))

(OBJECTPROPERTY(c.id, ‘IsUserTable’) = 1) 是表,  (OBJECTPROPERTY(c.id, ‘IsView’) = 1) 是视图

关于 OBJECTPROPERTY 的详细用法和参数, 请查看: http://technet.microsoft.com/zh-cn/library/ms176105(v=sql.90).aspx