如何获取.NET应用程序设置文件user.config的路径

Davinci Configurator之User Config File配置功能 Davinci Configurator 阅读详情

如何获取.NET应用程序设置文件user.config的路径

朱二(2008.11 转载请注明作者)

最近在开发一个.NET项目的时,需要在客户端软件中保存用户的一些设置,比如是否在登录框中保存上次登录名等信息,就用到了.NET中的应用程序设置功能。如果使用用户范围的设置,程序会在磁盘上创建user.config用来存储修改后设置值,对 user.config所在的文件夹,我产生了一些兴趣,并做了一些研究。现举个例子来说明:
C:/Documents and Settings/Admin/Local Settings/Application Data/Microsoft/test.exe_Url_3ypvtlafqkef0gkp1kl5i2idjssaxajb/1.0.0.0/user.config
其中
“C:/Documents and Settings/Admin/Local Settings/Application Data”是LocalApplicationData特殊文件夹
“Microsoft”程序集的厂商名称
“Admin”是当前Windows用户名
“test.exe”是程序集友好名称
“1.0.0.0”是程序集版本
“user.config”是存储用户配置信息的文件的文件名
“Url_3ypvtlafqkef0gkp1kl5i2idjssaxajb”该字符串是将程序集的厂商信息、版本信息、绝对路径进行哈希计算,得到的唯一值,可避免不同的程序生成相同的文件路径。

如果要想通过编程的方式对user.config文件做一些灵活的控制,就必须得到该文件的绝对路径,为了获取.NET生成user.config唯

一路径的方法,笔者使用Reflector反编译了System.Config程序集,终于得到了其中的方法,做了一些简化。现做一些介绍:
(1)ClientConfigPaths类,只有一个public方法GetUserConfigFilePath,此方法即可获取user.config的绝对路径;
(2)StringUtil类,一个辅助类,用来做一些字符串操作
(3)使用方法:

  1.   ClientConfigPaths ccp = new ClientConfigPaths();
  2.   textBox1.Text = ccp.GetUserConfigFilePath();

以下的代码笔者做了一些简化的同时也做了一些限制,即只适用于从本地磁盘加载的程序集。
注意:如果是从internet加载或者使用clickonce部署的程序集请不要使用该方法。

  1.     //ClientConfigPaths类
  2.     using Microsoft.Win32;
  3.     using System;
  4.     using System.Collections;
  5.     using System.Diagnostics;
  6.     using System.Globalization;
  7.     using System.IO;
  8.     using System.Reflection;
  9.     using System.Runtime.CompilerServices;
  10.     using System.Runtime.InteropServices;
  11.     using System.Runtime.Serialization.Formatters.Binary;
  12.     using System.Security.Cryptography;
  13.     using System.Security.Permissions;
  14.     using System.Security.Policy;
  15.     using System.Text;
  16.     internal class ClientConfigPaths
  17.     {
  18.         private string _applicationConfigUri;
  19.         private string _applicationUri;
  20.         private string _companyName;
  21.         private bool _includesUserConfig;
  22.         private string _productName;
  23.         private string _productVersion;
  24.         private const string ClickOnceDataDirectory = "DataDirectory";
  25.         private const string ConfigExtension = ".config";
  26.         private const string FILE_URI = "file:";
  27.         private const string FILE_URI_LOCAL = "file:///";
  28.         private const string FILE_URI_UNC = "file://";
  29.         private const string HTTP_URI = "http://";
  30.         private const int MAX_LENGTH_TO_USE = 0x19;
  31.         private const int MAX_PATH = 260;
  32.         private const string PathDesc = "Path";
  33.         private static char[] s_Base32Char = new char[] { 
  34.             'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 
  35.             'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5'
  36.          };
  37.         private static SecurityPermission s_controlEvidencePerm;
  38.         private static SecurityPermission s_serializationPerm;
  39.         private const string StrongNameDesc = "StrongName";
  40.         private const string UrlDesc = "Url";
  41.         internal const string UserConfigFilename = "user.config";
  42.         public string GetUserConfigFilePath()
  43.         {
  44.             string exePath = null;
  45.             bool includeUserConfig = true;
  46.             string UserConfigFilePath = "";
  47.             this._includesUserConfig = includeUserConfig;
  48.             Assembly exeAssembly = null;
  49.             string codeBase = null;
  50.             string applicationFilename = null;
  51.             if (exePath == null)
  52.             {
  53.                 AppDomainSetup setupInformation = AppDomain.CurrentDomain.SetupInformation;
  54.                 this._applicationConfigUri = setupInformation.ConfigurationFile;
  55.                 exeAssembly = Assembly.GetEntryAssembly();
  56.                     codeBase = exeAssembly.CodeBase;
  57.                     bool flag = false;
  58.                     if (StringUtil.StartsWithIgnoreCase(codeBase, "file:///"))
  59.                     {
  60.                         flag = true;
  61.                         codeBase = codeBase.Substring("file:///".Length);
  62.                     }
  63.                     else if (StringUtil.StartsWithIgnoreCase(codeBase, "file://"))
  64.                     {
  65.                         flag = true;
  66.                         codeBase = codeBase.Substring("file:".Length);
  67.                     }
  68.                     if (flag)
  69.                     {
  70.                         codeBase = codeBase.Replace('/', '//');
  71.                         applicationFilename = codeBase;
  72.                     }
  73.                     else
  74.                     {
  75.                         codeBase = exeAssembly.EscapedCodeBase;
  76.                     }
  77.             }
  78.             else
  79.             {
  80.                 codeBase = Path.GetFullPath(exePath);
  81.                 if (!File.Exists(codeBase))
  82.                 {
  83.                     throw new Exception();
  84.                 }
  85.                 applicationFilename = codeBase;
  86.             }
  87.             if (this._applicationConfigUri == null)
  88.             {
  89.                 this._applicationConfigUri = codeBase + ".config";
  90.             }
  91.             this._applicationUri = codeBase;
  92.             if ((exePath == null) && this._includesUserConfig)
  93.             {
  94.                 this.SetNamesAndVersion(applicationFilename, exeAssembly, false);
  95.                 string str5 = this.Validate(this._companyName, true);
  96.                 string str6 = this.Validate(AppDomain.CurrentDomain.FriendlyName, true);
  97.                 string str7 = !string.IsNullOrEmpty(this._applicationUri) ? this._applicationUri.ToLower
  98. (CultureInfo.InvariantCulture) : null;
  99.                 string str8 = !string.IsNullOrEmpty(str6) ? str6 : this.Validate(this._productName, true);
  100.                 string typeAndHashSuffix = this.GetTypeAndHashSuffix(AppDomain.CurrentDomain, str7);
  101.                     string str10 = (!string.IsNullOrEmpty(str8) && !string.IsNullOrEmpty(typeAndHashSuffix)) ? 
  102. (str8 + typeAndHashSuffix) : null;
  103.                     string str11 = this.Validate(this._productVersion, false);
  104.                     string str12 = this.CombineIfValid(this.CombineIfValid(str5, str10), str11);
  105.                     string path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
  106.                     if (Path.IsPathRooted(path))
  107.                     {
  108.                         UserConfigFilePath = this.CombineIfValid(path, str12);
  109.                         UserConfigFilePath = this.CombineIfValid(UserConfigFilePath, "user.config");
  110.                     }
  111.             }
  112.             return UserConfigFilePath;
  113.         }
  114.         private string CombineIfValid(string path1, string path2)
  115.         {
  116.             string str = null;
  117.             if ((path1 != null) && (path2 != null))
  118.             {
  119.                 try
  120.                 {
  121.                     string str2 = Path.Combine(path1, path2);
  122.                     if (str2.Length < 260)
  123.                     {
  124.                         str = str2;
  125.                     }
  126.                 }
  127.                 catch
  128.                 {
  129.                 }
  130.             }
  131.             return str;
  132.         }
  133.         private static object GetEvidenceInfo(AppDomain appDomain, string exePath, out string typeName)
  134.         {
  135.             ControlEvidencePermission.Assert();
  136.             Evidence evidence = appDomain.Evidence;
  137.             StrongName sn = null;
  138.             Url url = null;
  139.             if (evidence != null)
  140.             {
  141.                 IEnumerator hostEnumerator = evidence.GetHostEnumerator();
  142.                 object current = null;
  143.                 while (hostEnumerator.MoveNext())
  144.                 {
  145.                     current = hostEnumerator.Current;
  146.                     if (current is StrongName)
  147.                     {
  148.                         sn = (StrongName) current;
  149.                         break;
  150.                     }
  151.                     if (current is Url)
  152.                     {
  153.                         url = (Url) current;
  154.                     }
  155.                 }
  156.             }
  157.             object obj3 = null;
  158.             if (sn != null)
  159.             {
  160.                 obj3 = MakeVersionIndependent(sn);
  161.                 typeName = "StrongName";
  162.                 return obj3;
  163.             }
  164.             if (url != null)
  165.             {
  166.                 obj3 = url.Value.ToUpperInvariant();
  167.                 typeName = "Url";
  168.                 return obj3;
  169.             }
  170.             if (exePath != null)
  171.             {
  172.                 obj3 = exePath;
  173.                 typeName = "Path";
  174.                 return obj3;
  175.             }
  176.             typeName = null;
  177.             return obj3;
  178.         }
  179.         private static string GetHash(Stream s)
  180.         {
  181.             byte[] buffer;
  182.             using (SHA1 sha = new SHA1CryptoServiceProvider())
  183.             {
  184.                 buffer = sha.ComputeHash(s);
  185.             }
  186.             return ToBase32StringSuitableForDirName(buffer);
  187.         }
  188.         private string GetTypeAndHashSuffix(AppDomain appDomain, string exePath)
  189.         {
  190.             string str = null;
  191.             string typeName = null;
  192.             object graph = null;
  193.             graph = GetEvidenceInfo(appDomain, exePath, out typeName);
  194.             if ((graph != null) && !string.IsNullOrEmpty(typeName))
  195.             {
  196.                 MemoryStream serializationStream = new MemoryStream();
  197.                 BinaryFormatter formatter = new BinaryFormatter();
  198.                 SerializationFormatterPermission.Assert();
  199.                 formatter.Serialize(serializationStream, graph);
  200.                 serializationStream.Position = 0L;
  201.                 string hash = GetHash(serializationStream);
  202.                 if (!string.IsNullOrEmpty(hash))
  203.                 {
  204.                     str = "_" + typeName + "_" + hash;
  205.                 }
  206.             }
  207.             return str;
  208.         }
  209.         private static StrongName MakeVersionIndependent(StrongName sn)
  210.         {
  211.             return new StrongName(sn.PublicKey, sn.Name, new Version(0, 0, 0, 0));
  212.         }
  213.         private void SetNamesAndVersion(string applicationFilename, Assembly exeAssembly, bool isHttp)
  214.         {
  215.             Type reflectedType = null;
  216.             if (exeAssembly != null)
  217.             {
  218.                 object[] customAttributes = exeAssembly.GetCustomAttributes(typeof(AssemblyCompanyAttribute), 
  219. false);
  220.                 if ((customAttributes != null) && (customAttributes.Length > 0))
  221.                 {
  222.                     this._companyName = ((AssemblyCompanyAttribute) customAttributes[0]).Company;
  223.                     if (this._companyName != null)
  224.                     {
  225.                         this._companyName = this._companyName.Trim();
  226.                     }
  227.                 }
  228.                 customAttributes = exeAssembly.GetCustomAttributes(typeof(AssemblyProductAttribute), false);
  229.                 if ((customAttributes != null) && (customAttributes.Length > 0))
  230.                 {
  231.                     this._productName = ((AssemblyProductAttribute) customAttributes[0]).Product;
  232.                     if (this._productName != null)
  233.                     {
  234.                         this._productName = this._productName.Trim();
  235.                     }
  236.                 }
  237.                 this._productVersion = exeAssembly.GetName().Version.ToString();
  238.                 if (this._productVersion != null)
  239.                 {
  240.                     this._productVersion = this._productVersion.Trim();
  241.                 }
  242.             }
  243.             if (!isHttp && ((string.IsNullOrEmpty(this._companyName) || string.IsNullOrEmpty(this._productName)) || 
  244. string.IsNullOrEmpty(this._productVersion)))
  245.             {
  246.                 string fileName = null;
  247.                 if (exeAssembly != null)
  248.                 {
  249.                     MethodInfo entryPoint = exeAssembly.EntryPoint;
  250.                     if (entryPoint != null)
  251.                     {
  252.                         reflectedType = entryPoint.ReflectedType;
  253.                         if (reflectedType != null)
  254.                         {
  255.                             fileName = reflectedType.Module.FullyQualifiedName;
  256.                         }
  257.                     }
  258.                 }
  259.                 if (fileName == null)
  260.                 {
  261.                     fileName = applicationFilename;
  262.                 }
  263.                 if (fileName != null)
  264.                 {
  265.                     FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(fileName);
  266.                     if (versionInfo != null)
  267.                     {
  268.                         if (string.IsNullOrEmpty(this._companyName))
  269.                         {
  270.                             this._companyName = versionInfo.CompanyName;
  271.                             if (this._companyName != null)
  272.                             {
  273.                                 this._companyName = this._companyName.Trim();
  274.                             }
  275.                         }
  276.                         if (string.IsNullOrEmpty(this._productName))
  277.                         {
  278.                             this._productName = versionInfo.ProductName;
  279.                             if (this._productName != null)
  280.                             {
  281.                                 this._productName = this._productName.Trim();
  282.                             }
  283.                         }
  284.                         if (string.IsNullOrEmpty(this._productVersion))
  285.                         {
  286.                             this._productVersion = versionInfo.ProductVersion;
  287.                             if (this._productVersion != null)
  288.                             {
  289.                                 this._productVersion = this._productVersion.Trim();
  290.                             }
  291.                         }
  292.                     }
  293.                 }
  294.             }
  295.             if (string.IsNullOrEmpty(this._companyName) || string.IsNullOrEmpty(this._productName))
  296.             {
  297.                 string str2 = null;
  298.                 if (reflectedType != null)
  299.                 {
  300.                     str2 = reflectedType.Namespace;
  301.                 }
  302.                 if (string.IsNullOrEmpty(this._productName))
  303.                 {
  304.                     if (str2 != null)
  305.                     {
  306.                         int num = str2.LastIndexOf(".", StringComparison.Ordinal);
  307.                         if ((num != -1) && (num < (str2.Length - 1)))
  308.                         {
  309.                             this._productName = str2.Substring(num + 1);
  310.                         }
  311.                         else
  312.                         {
  313.                             this._productName = str2;
  314.                         }
  315.                         this._productName = this._productName.Trim();
  316.                     }
  317.                     if (string.IsNullOrEmpty(this._productName) && (reflectedType != null))
  318.                     {
  319.                         this._productName = reflectedType.Name.Trim();
  320.                     }
  321.                     if (this._productName == null)
  322.                     {
  323.                         this._productName = string.Empty;
  324.                     }
  325.                 }
  326.                 if (string.IsNullOrEmpty(this._companyName))
  327.                 {
  328.                     if (str2 != null)
  329.                     {
  330.                         int index = str2.IndexOf(".", StringComparison.Ordinal);
  331.                         if (index != -1)
  332.                         {
  333.                             this._companyName = str2.Substring(0, index);
  334.                         }
  335.                         else
  336.                         {
  337.                             this._companyName = str2;
  338.                         }
  339.                         this._companyName = this._companyName.Trim();
  340.                     }
  341.                     if (string.IsNullOrEmpty(this._companyName))
  342.                     {
  343.                         this._companyName = this._productName;
  344.                     }
  345.                 }
  346.             }
  347.             if (string.IsNullOrEmpty(this._productVersion))
  348.             {
  349.                 this._productVersion = "1.0.0.0";
  350.             }
  351.         }
  352.         private static string ToBase32StringSuitableForDirName(byte[] buff)
  353.         {
  354.             StringBuilder builder = new StringBuilder();
  355.             int length = buff.Length;
  356.             int num7 = 0;
  357.             do
  358.             {
  359.                 byte num = (num7 < length) ? buff[num7++] : ((byte) 0);
  360.                 byte num2 = (num7 < length) ? buff[num7++] : ((byte) 0);
  361.                 byte index = (num7 < length) ? buff[num7++] : ((byte) 0);
  362.                 byte num4 = (num7 < length) ? buff[num7++] : ((byte) 0);
  363.                 byte num5 = (num7 < length) ? buff[num7++] : ((byte) 0);
  364.                 builder.Append(s_Base32Char[num & 0x1f]);
  365.                 builder.Append(s_Base32Char[num2 & 0x1f]);
  366.                 builder.Append(s_Base32Char[index & 0x1f]);
  367.                 builder.Append(s_Base32Char[num4 & 0x1f]);
  368.                 builder.Append(s_Base32Char[num5 & 0x1f]);
  369.                 builder.Append(s_Base32Char[((num & 0xe0) >> 5) | ((num4 & 0x60) >> 2)]);
  370.                 builder.Append(s_Base32Char[((num2 & 0xe0) >> 5) | ((num5 & 0x60) >> 2)]);
  371.                 index = (byte) (index >> 5);
  372.                 if ((num4 & 0x80) != 0)
  373.                 {
  374.                     index = (byte) (index | 8);
  375.                 }
  376.                 if ((num5 & 0x80) != 0)
  377.                 {
  378.                     index = (byte) (index | 0x10);
  379.                 }
  380.                 builder.Append(s_Base32Char[index]);
  381.             }
  382.             while (num7 < length);
  383.             return builder.ToString();
  384.         }
  385.         private string Validate(string str, bool limitSize)
  386.         {
  387.             string str2 = str;
  388.             if (!string.IsNullOrEmpty(str2))
  389.             {
  390.                 foreach (char ch in Path.GetInvalidFileNameChars())
  391.                 {
  392.                     str2 = str2.Replace(ch, '_');
  393.                 }
  394.                 str2 = str2.Replace(' ', '_');
  395.                 if (limitSize)
  396.                 {
  397.                     str2 = (str2.Length > 0x19) ? str2.Substring(0, 0x19) : str2;
  398.                 }
  399.             }
  400.             return str2;
  401.         }
  402.         private static SecurityPermission ControlEvidencePermission
  403.         {
  404.             get
  405.             {
  406.                 if (s_controlEvidencePerm == null)
  407.                 {
  408.                     s_controlEvidencePerm = new SecurityPermission(SecurityPermissionFlag.ControlEvidence);
  409.                 }
  410.                 return s_controlEvidencePerm;
  411.             }
  412.         }
  413.         private static SecurityPermission SerializationFormatterPermission
  414.         {
  415.             get
  416.             {
  417.                 if (s_serializationPerm == null)
  418.                 {
  419.                     s_serializationPerm = new SecurityPermission(SecurityPermissionFlag.SerializationFormatter);
  420.                 }
  421.                 return s_serializationPerm;
  422.             }
  423.         }
  424.     }

StringUtil类

 
  1.   //StringUtil类
  2.     using System;
  3.     internal static class StringUtil
  4.     {
  5.         internal static bool EqualsIgnoreCase(string s1, string s2)
  6.         {
  7.             return string.Equals(s1, s2, StringComparison.OrdinalIgnoreCase);
  8.         }
  9.         internal static bool EqualsNE(string s1, string s2)
  10.         {
  11.             if (s1 == null)
  12.             {
  13.                 s1 = string.Empty;
  14.             }
  15.             if (s2 == null)
  16.             {
  17.                 s2 = string.Empty;
  18.             }
  19.             return string.Equals(s1, s2, StringComparison.Ordinal);
  20.         }
  21.         internal static string[] ObjectArrayToStringArray(object[] objectArray)
  22.         {
  23.             string[] array = new string[objectArray.Length];
  24.             objectArray.CopyTo(array, 0);
  25.             return array;
  26.         }
  27.         internal static bool StartsWith(string s1, string s2)
  28.         {
  29.             if (s2 == null)
  30.             {
  31.                 return false;
  32.             }
  33.             return (0 == string.Compare(s1, 0, s2, 0, s2.Length, StringComparison.Ordinal));
  34.         }
  35.         internal static bool StartsWithIgnoreCase(string s1, string s2)
  36.         {
  37.             if (s2 == null)
  38.             {
  39.                 return false;
  40.             }
  41.             return (0 == string.Compare(s1, 0, s2, 0, s2.Length, StringComparison.OrdinalIgnoreCase));
  42.         }
  43.     }

 

C#配置文件深度解析:App.config与.settings文件的核心区别与实战策略 在软件开发中,配置文件是管理应用程序外部参数的核心机制,它允许开发者在不同环境中动态调整程序行为而无需重新编译。其原理是通过键值对或结构化数据存储设置,运行时由程序读取并应用。这一技术价值在于提升软件的可维护性、灵活性和部署效率,尤其在多环境部署和持续集成场景中至关重要。在C#开发领域,.NET Framework提供了两种经典的配置管理方案:基于XML的App.config文件和强类型的.settings文件。App.config作为底层配置基石,支持灵活的自定义配置节,但存在弱类型和魔法字符串的问题;而 阅读详情

相关推荐

C#配置文件App.config与.settings详解:原理、区别与应用场景

在.NET应用程序开发中,配置文件管理是构建可维护、可部署软件系统的关键技术环节。其核心原理在于通过结构化方式存储应用程序的运行时参数,实现行为的外部化控制,从而提升系统的灵活性和环境适应性。从技术价值角度看,良好的配置管理能显著降低代码与环境的耦合度,支持多环境部署(如开发、测试、生产),并增强应用的安全性。在工程实践中,配置系统通常需要兼顾通用性、类型安全性和开发体验。具体到C#和.NET Framework技术栈,开发者常会遇到App.config与.settings文件这两种配置管理方式。App.c

weixin_30298497的博客 377

c# 解决User.config文件损坏的问题

(2)在OnStartup启动执行函数中,加入.config文件监测,如果可以正常打开,则做一下备份,如果文件出现了损坏,则使用备份的文件。在写入.config文件时,软件异常退出,或者电脑关机,会发生User.config文件损坏的问题。(1)去除经常写入.config文件的程序,会降低发生概率;//监测config文件。/// 监测配置文件是否损坏。

wangqunzhi1的博客 1220

.NET配置系统演进与实战:从app.config到IConfiguration

配置管理是.NET应用运行时的核心基础设施,其本质是将外部参数安全、可扩展、可验证地注入程序生命周期。早期基于XML的ConfigurationManager采用静态单例模式,存在热更新失效、作用域污染和测试隔离难等问题;而.NET Core引入的IConfiguration则构建了可组合、可注入、不可变的管道式架构,支持JSON、环境变量、Key Vault等多源配置,并通过IOptions系列接口实现强类型绑定与动态监听。该机制不仅提升了微服务与云原生场景下的环境适应性,更成为金融、医疗等高合规系统实现

aobai7842的博客 356

.NET应用程序设置文件user.config

1.获取路径 1.引用System.Configuration System.Configuration.ConfigurationManager.OpenExeConfiguration (System.Configuration.ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath说明:必须存在user.config文件才会取到,...

博客 2142

.NET配置系统全解析:从app.config到IConfiguration的演进与实践

配置管理是.NET应用运行的基础能力,涉及配置加载、热重载、线程安全与多环境适配等核心机制。其本质并非简单读写XML或JSON文件,而是围绕配置源抽象、层级绑定、变更感知与生命周期管理构建的技术体系。.NET Framework依赖System.Configuration实现XML配置节扩展,.NET Core起则通过Microsoft.Extensions.Configuration提供可插拔的Provider模型,支持appsettings.json、环境变量、命令行等多源叠加与自动重载。关键技术价值在

as2886089的博客 446

深入解析STM32F40x CAN控制器的配置与优化

本文深入解析STM32F40x CAN控制器的配置与优化,涵盖基础工作模式、波特率计算、筛选器配置及中断管理等关键技术。通过实战案例和代码示例,帮助开发者高效配置CAN通信,提升工业控制系统的稳定性和性能。

weixin_26834815的博客 229

C#/WPF 修改用户配置 user.config 的路径

原文链接:https://stackoverflow.com/questions/2265271/custom-path-of-the-user-config 在 WPF 中,可以使用 user.config 去持久化配置,但是该文件是存储在 c 盘的用户文件夹下,不好移动和修改,且微软不提供修改的方法,因此使用下面的方法可以实现修改路径 新建一个类 CustomSettingsProvider 如下: class CustomSettingsProvider : SettingsProvider

chaoge_dgqb的博客 1877

Ollama最新快速上手指南:从安装到精通本地AI模型部署

想让Ollama跑你的"私房模型"?三种主流格式全支持,总有一款适合你!GGUF格式(推荐新手首选)创建Modelfile文件:执行创建命令:运行你的专属模型:PyTorch/Safetensors格式(适合进阶玩家)先用库测试模型能否正常加载确保模型结构完整后再导入Ollama官方文档有详细转换指南专业小贴士GGUF格式最轻量,PyTorch最灵活,Safetensors最安全遇到问题?试试用llama.cpp进行格式转换7B参数模型推荐使用q4_0量化级别想让AI用马里奥。

全世界的博客 2315

【Shell 命令集合 系统管理 】Linux 管理用户配置文件 userconf命令 使用指南

在Linux中,userconf命令用于管理用户配置文件。它可以帮助管理员修改和管理用户的配置文件,以满足特定的需求。

探索C++编程的奥秘,分享深入的技术见解和实践,旨在激发读者创造力与解决问题的思维。 752

基于OkHttp3+Retrofit2+RxJava3搭建响应式网络框架

本文介绍了一个基于OkHttp3+Retrofit3+RxJava3的响应式网络框架设计。该框架采用分层架构,OkHttp3负责底层网络请求,Retrofit3封装HTTP接口,RxJava3实现响应式流处理。核心亮点包括:1)高度解耦的分层设计;2)统一的异常处理和响应体封装;3)RxJava3实现线程切换和请求管理;4)MVVM架构适配,业务层只需关注数据逻辑。框架提供了完整的实现方案,包括全局配置、拦截器、响应转换、接口声明、仓库封装等组件,并支持生产环境扩展功能如Cookie持久化、Token刷新等

fuge2008的博客 880

别再手动查日志了!用Dify+Zabbix打造你的专属运维“嘴替”(保姆级配置流程)

本文详细介绍了如何利用Dify平台与Zabbix监控系统集成,构建智能运维对话系统,实现自然语言交互的运维管理。通过保姆级配置流程,帮助运维工程师提升查询效率、降低学习成本,打造企业级智能运维解决方案。

weixin_27298377的博客 459

如何获取.NET应用程序设置文件config的路径

最近在学习.NET的时,需要在客户端软件中保存用户的一些设置,比如是否在登录框中保存上次登录名等信息,就用到了.NET中的应用程序设置功能。如果使用用户范围的设置,程序会在磁盘上创建user.config用来存储修改后设置值,对 user.config所在的文件夹,我产生了一些兴趣,并做了一些研究。现举个例子来说明:C:/Documents and Settings/Admin/Local Set

祈离的专栏 2868

AI Agent实战:WorkBuddy安装部署、任务执行与模型接入全教程

AI Agent是当前自动化办公与智能工作流的核心技术,它区别于传统问答式AI,能够理解目标、拆解任务并调用工具交付完整成果。其底层原理基于任务规划、工具调用与结果验证的循环机制,让机器从“提供建议”进化为“完成任务”。在工程实践中,合理配置模型服务(如接入DeepSeek)、设计标准化Skill(技能包)与自定义指令,可以显著提升Agent在报告生成、数据分析、竞品调研等场景中的稳定性与效率。WorkBuddy作为典型的任务式AI工作台,为运营、产品、开发等多角色提供了统一入口,覆盖安装部署、任务描述公式

weixin_26712075的博客 300

DotNET应用程序设置的使用小结

DotNET应用程序设置的使用小结朱二(2008.11 转载请注明作者) 最近在开发一个.NET项目的时,需要在客户端软件中保存用户的一些设置,比如是否在登录框中保存上次登录名等信息,就用到了.NET中的应用程序设置功能,在使用中有一些心得,在这里和大家分享一下,如有不妥之处也请大家严厉指出。    一、应用程序设置是 Microsoft Visual Studio 2005 新功能,

人生倒计时 2035

基于CNN的三相故障识别算法及实现(Matlab)

通过预处理数据、构建CNN模型、训练与评估模型等步骤,我们可以准确快速地识别三相故障。现代电力系统中,三相故障是一种常见的故障情况,可以导致电网中断、设备损坏甚至火灾等严重后果。本文将介绍基于卷积神经网络(CNN)的三相故障识别算法,并提供Matlab源代码实现。首先,将原始信号分为训练集和测试集。然后,对输入信号进行归一化处理,确保数据在合适的范围内。CNN适用于处理二维数据,所以我们可以将输入信号看作是时间序列数据和特征(如电压、电流等)的二维矩阵。在开始之前,我们需要一个包含正常和故障样本的数据集。

学习使你进步。 391

回归预测 | MATLAB实现MPR多元多项式回归

回归预测 | MATLAB实现MPR多元多项式回归

机器学习之心的博客,关注并私信文章链接,获取对应文章源码和数据。 1648

Java获取jar包路径的正确姿势:user.dir、ApplicationHome与classpath辨析

在Java应用部署中,‘获取jar包路径’是基础却高频出错的操作。其本质涉及JVM工作目录(user.dir)的启动上下文依赖、类加载器对classpath的资源定位机制,以及Spring Boot提供的ApplicationHome抽象层。理解三者差异,才能避免IDE调试正常而生产环境失效的陷阱。user.dir仅反映进程启动时pwd,不等于jar物理位置;classpath是逻辑资源搜索路径,无法直接映射文件系统;而ApplicationHome通过MANIFEST.MF精准定位jar文件,成为跨环境最

weixin_34212762的博客 501

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

.NET下fckeditor动态设置文件上传路径,解决多用户多路径的问题。

首先看一下FCKeditor是如何获取用户的文件夹路径设置的,以及获取的顺序: FCKeditor.net获取上传路径文件是:FileWorkerBase.cs,打开找到以下部分view plaincopy to clipboardprint?protected string UserFilesPath{get{if ( sUserFilesPath == null ){// 第一回从...

dfawbv6953的博客 132

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

.NET下fckeditor动态设置文件上传路径

<br />首先看一下FCKeditor是如何获取用户的文件夹路径设置的,以及获取的顺序:<br />FCKeditor.net获取上传路径文件是:FileWorkerBase.cs,打开找到以下部分view plaincopy to clipboardprint?<br />protected string UserFilesPath<br />{<br />get<br />{<br />if ( sUserFilesPath == null )<br />{<br />// 第一回从applicati

冯伟楠的专栏 406

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

C#配置管理:App.config与.settings文件的原理、实践与演进

在软件开发中,配置管理是连接代码与运行环境的关键桥梁,它决定了应用在不同环境下的行为。其核心原理在于将外部化配置与代码逻辑分离,通过配置文件动态控制程序行为,从而提升应用的可维护性和部署灵活性。从技术价值看,良好的配置管理能实现环境隔离、安全管控和运行时调整,是构建企业级应用的基础。在.NET生态中,配置系统经历了从XML到JSON的演进,但理解其底层机制至关重要。本文聚焦于C#开发中经典的App.config与.settings文件这对组合,深入解析其设计哲学、强类型访问机制以及在实际项目中的配置策略,涵

weixin_33966095的博客 364

【Sql】win11系统安装sqlserver2008r2数据库,找不到文件user.config line 5

【Sql】win11系统安装sqlserver2008r2数据库,找不到文件user.config line 5

努力不懈的为广大客户提供优质的产品与真诚、贴心、专业的服务! 6072

allegro大十字光标设置方法:TaoToken统一Key接入Cline的config.toml骨架

Allegro大十字光标设置方法:在User Preferences的Display→Cursor中将pcb_cursor改为infinite即可生效。同时用TaoToken统一Key为Cline写config.toml骨架,Base URL填https://taotoken.net/api,换模型只改model字段。官网:https://taotoken.net/?utm_source=taotoken_aicg_blog_end

Ceshi01的博客 144

ASP.NET任意文件读取漏洞:原理、复现与防御实践

路径遍历(Path Traversal)是Web安全中一种经典的高危漏洞,其核心原理在于应用程序未对用户输入的文件路径参数进行充分验证和过滤,导致攻击者能够通过构造包含目录遍历序列(如../)的恶意输入,访问并读取服务器文件系统中的任意文件。这类漏洞的技术价值在于其利用门槛低、危害性高,常成为企业内网渗透测试中横向移动和敏感信息收集的关键突破口。在ASP.NET等企业级应用开发场景中,由于开发人员安全意识不足或框架使用不当,类似汇智ERP系统filehandle.aspx文件存在的任意文件读取缺陷屡见不鲜。

434

Codex工作区设置指南:用TaoToken统一Key管理config.toml与文件保存位置

Codex多项目开发常遇Key散落与文件保存位置混乱,本文用TaoToken统一Key入口,给出可复制的config.toml骨架,覆盖全局与项目级配置,并附curl验证与落盘路径排查步骤。访问TaoToken官网 https://taotoken.net/?utm_source=taotoken_aicg_blog_end 获取Key,让每个工作区文件保存位置清晰可控。

weixin_35756690的博客 10
上一篇: DotNET应用程序设置的使用小结
下一篇: C#如何编程方式获取计算机主板序列号
「已注销」
博客等级 码龄25年 93粉丝 101原创
评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值