【问题标题】:How to resolve the Error " Unable to locate local.config.user file. Make sure you have run 'build.cmd local' '如何解决错误“无法找到 local.config.user 文件。确保您已运行 'build.cmd local'”
【发布时间】:2016-04-23 04:19:57
【问题描述】:

我正在尝试在本地主机上运行此测试,但它一直抛出错误“无法找到 local.config.user 文件。请确保您已运行 'build.cmd local'”

那么如何找到 local.config.user 文件呢?或者如何在本地运行 build.cmd ?请尝试查看下面的代码

    using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using Microsoft.WindowsAzure.ServiceRuntime;

namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.Common.Configurations
{
    public class ConfigurationProvider : IConfigurationProvider, IDisposable
    {
        readonly Dictionary<string, string> configuration = new Dictionary<string, string>();
        EnvironmentDescription environment = null;
        const string ConfigToken = "config:";
        bool _disposed = false;

        public string GetConfigurationSettingValue(string configurationSettingName)
        {
            return this.GetConfigurationSettingValueOrDefault(configurationSettingName, string.Empty);
        }

        public string GetConfigurationSettingValueOrDefault(string configurationSettingName, string defaultValue)
        {
            try
            {
                if (!this.configuration.ContainsKey(configurationSettingName))
                {
                    string configValue = string.Empty;
                    bool isEmulated = true;
                    bool isAvailable = false;
                    try
                    {
                        isAvailable = RoleEnvironment.IsAvailable;
                    }
                    catch (TypeInitializationException) { }
                    if (isAvailable)
                    {
                        configValue = RoleEnvironment.GetConfigurationSettingValue(configurationSettingName);
                        isEmulated = RoleEnvironment.IsEmulated;
                    }
                    else
                    {
                        configValue = ConfigurationManager.AppSettings[configurationSettingName];
                        isEmulated = Environment.CommandLine.Contains("iisexpress.exe") ||
                            Environment.CommandLine.Contains("WebJob.vshost.exe");
                    }
                    if (isEmulated && (configValue != null && configValue.StartsWith(ConfigToken, StringComparison.OrdinalIgnoreCase)))
                    {
                        if (environment == null)
                        {
                            LoadEnvironmentConfig();
                        }

                        configValue = 
                            environment.GetSetting(configValue.Substring(configValue.IndexOf(ConfigToken, StringComparison.Ordinal) + ConfigToken.Length));
                    }
                    try
                    {
                        this.configuration.Add(configurationSettingName, configValue);
                    }
                    catch (ArgumentException)
                    {
                        // at this point, this key has already been added on a different
                        // thread, so we're fine to continue
                    }
                }
            }
            catch (RoleEnvironmentException)
            {
                if (string.IsNullOrEmpty(defaultValue))
                    throw;

                this.configuration.Add(configurationSettingName, defaultValue);
            }
            return this.configuration[configurationSettingName];
        }

        void LoadEnvironmentConfig()
        {
            var executingPath = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);

            // Check for build_output
            int buildLocation = executingPath.IndexOf("Build_Output", StringComparison.OrdinalIgnoreCase);
            if (buildLocation >= 0)
            {
                string fileName = executingPath.Substring(0, buildLocation) + "local.config.user";
                if (File.Exists(fileName))
                {
                    this.environment = new EnvironmentDescription(fileName);
                    return;
                }
            }

            // Web roles run in there app dir so look relative
            int location = executingPath.IndexOf("Web\\bin", StringComparison.OrdinalIgnoreCase);

            if (location == -1)
            {
                location = executingPath.IndexOf("WebJob\\bin", StringComparison.OrdinalIgnoreCase);
            }
           if (location >=0)
            {
              string fileName = executingPath.Substring(0, location) + "..\\local.config.user";
                if (File.Exists(fileName))
                {
                    this.environment = new EnvironmentDescription(fileName);
                    return;
                }
            }

            throw new ArgumentException("Unable to locate local.config.user file.  Make sure you have run 'build.cmd local'.");
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                if (environment != null)
                {
                    environment.Dispose();
                }
            }

            _disposed = true;
        }

        ~ConfigurationProvider()
        {
            Dispose(false);
        }
    }
}

您好,先生,谢谢您的帮助。我试过“Build.cmd build”和“Build.cmd local”,它给了我这个错误。

【问题讨论】:

    标签: c# .net asp.net-mvc azure


    【解决方案1】:

    通常,在 Visual Studio 解决方案的根文件夹中,您应该有一个 build.cmd 文件。

    您需要以管理员身份运行 Developer Command Prompt for VS2015(或安装其他版本的 Visual Studio,使用开始菜单中的 Windows 搜索)并将目录 (cd [directory with solution]) 更改为上述解决方案的根文件夹,然后键入并通过单击 Enter 运行 build.cmd local

    【讨论】:

    • 您好,先生,非常感谢您的帮助。我已经更新了我的问题,我是否缺少文件?
    • @nicko_yuan 你好,很抱歉这么晚的回复,你看到 build.cmd 不喜欢路径中的空格。尝试将您的文件夹“Visual Studio Projects”重命名为“VSProjects”(或“VisualStudioProjects”,但我建议保持简短,因为路径长度有限制),它应该可以工作。
    猜你喜欢
    • 2018-04-12
    • 2019-09-25
    • 2016-12-05
    • 1970-01-01
    • 1970-01-01
    • 2021-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多