.net 编译报错:编辑器或项目正在尝试签出在内存中修改的文件,这将导致保存该文件。

1,报错提示:

编辑器或项目正在尝试签出在内存中修改的文件,这将导致保存该文件。

在生成过程中保存文件是危险的,这可能会在将来导致不正确的生成输出。

是否仍然继续签出?

2,原因:licenses.licx属性设为了只读.

3,解决:

  a,搜索''licenses.licx',去掉只读属性;

  b,LicensesClear.exe放到项目根目录下,双击执行.

  递归取消licenses.licx只读属性,源码


  static class Program
    {
        //添加外部工具时参数可选为解决方案目录
        static void Main(string[] args)
        {
            if (args == null || args.Length <= 0)
            {
                //LicensesClear(new DirectoryInfo(FilePathHelper.GetDirectoryName(FilePathHelper.GetAbsolutePath(string.Empty))));
            }
            else
            {
                foreach (string path in args)
                    if (path != null && Directory.Exists(path))
                        LicensesClear(new DirectoryInfo(path));
            }

        }

        //递归取消licenses.licx文件的只读属性
        private static void LicensesClear(DirectoryInfo directoryInfo)
        {
            DirectoryInfo subDirInfo;
            FileInfo subFileInfo;
            foreach (FileSystemInfo sysInfo in directoryInfo.GetFileSystemInfos())
            {

                if ((subDirInfo = sysInfo as DirectoryInfo) != null)//存在子级文件
                {
                    LicensesClear(subDirInfo);
                }//设置文件只读
                else if ((subFileInfo = sysInfo as FileInfo) != null && subFileInfo.Name.ToLower().Equals("licenses.licx"))
                {
                    subFileInfo.IsReadOnly = false;//去掉只读
                    if (subFileInfo.Length > 0)
                        using (FileStream fs = subFileInfo.OpenWrite())
                        {
                            fs.Seek(0, SeekOrigin.Begin);
                            fs.SetLength(0);
                        }
                    Console.WriteLine(string.Format("已清理:{0}", subFileInfo.FullName));
                }


            }
        }
    }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值