You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行dotnet new console命令时出现UnauthorizedAccessException错误求助

执行dotnet new console命令时出现UnauthorizedAccessException错误求助

我尝试在任意终端运行dotnet new console命令,但每次都返回权限拒绝的错误,具体报错信息如下:

Unhandled exception: System.UnauthorizedAccessException: Access to the path 'C:\Users\Trist\.templateengine\dotnetcli\v7.0.101' is denied.

at System.IO.FileSystem.CreateDirectory(String fullPath, Byte[] securityDescriptor)

at System.IO.Directory.CreateDirectory(String path)

at Microsoft.TemplateEngine.Utils.PhysicalFileSystem.CreateDirectory(String path)

at Microsoft.TemplateEngine.Cli.Commands.BaseCommand.CreateEnvironmentSettings(GlobalArgs args, ParseResult parseResult)

at Microsoft.TemplateEngine.Cli.Commands.BaseCommand`1.InvokeAsync(InvocationContext context)

at Microsoft.TemplateEngine.Cli.Commands.BaseCommand`1.Invoke(InvocationContext context)

at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()

--- End of stack trace from previous location ---

at Microsoft.DotNet.Cli.Parser.<>c__DisplayClass17_0.<<UseParseErrorReporting>b__0>d.MoveNext()

--- End of stack trace from previous location ---

at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass11_0.<<UseHelp>b__0>d.MoveNext()

--- End of stack trace from previous location ---

at System.CommandLine.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__17_0>d.MoveNext()

--- End of stack trace from previous location ---

at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass15_0.<<UseParseDirective>b__0>d.MoveNext()

--- End of stack trace from previous location ---

at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass7_0.<<UseExceptionHandler>b__0>d.MoveNext()

我已经给该路径的所有可用用户开放了权限,也重新安装并修复了.NET SDK,但折腾了几个小时还是没解决,也没找到类似的问题案例,现在毫无头绪,恳请大家帮忙!


可能的解决办法:

  • 手动删除目标目录后重试
    先关闭所有和.NET相关的程序(比如终端、Visual Studio、Rider等),然后手动删除C:\Users\Trist\.templateengine\dotnetcli\v7.0.101这个目录。之后重新打开终端运行dotnet new console,让系统重新创建这个目录——有时候旧目录的权限配置已经损坏,重建就能解决问题。

  • 以管理员身份运行终端
    右键点击你使用的终端(CMD、PowerShell或者Windows Terminal都可以),选择「以管理员身份运行」,然后再执行dotnet new console命令。管理员权限通常能突破普通用户的权限限制,顺利创建所需目录。

  • 修复目录的继承权限
    右键点击C:\Users\Trist\.templateengine文件夹,选择「属性」→「安全」→「高级」,检查权限是否开启了继承。如果之前手动修改过权限导致继承被关闭,点击「启用继承」并保存,之后再重试命令。

  • 重新以管理员身份安装.NET SDK
    先卸载当前的.NET SDK,然后找到安装包,右键选择「以管理员身份运行」重新安装。确保安装过程中没有权限拦截,这样能保证SDK相关的目录和文件权限配置正确。

备注:内容来源于stack exchange,提问作者Tristyp

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.23 07:54:08