简体   繁体   English

JetBrains Rider IDE => 托管环境

[英]JetBrains rider IDE => Hosting Environment

enter image description here I am trying to move from Visual Studio 2022 to JetBrains rider with my .NET full-stack project.在此处输入图像描述我正在尝试使用我的 .NET 全栈项目从 Visual Studio 2022 迁移到 JetBrains Rider。

I am using Webpack for my front-end side if it gives anyone a clue (I also run the Webpack command like in my vs2002).如果它给任何人一个线索,我将使用 Webpack 作为我的前端(我也像在我的 vs2002 中一样运行 Webpack 命令)。

The problem which occurs is the HostingEnvironment.IsDevelopmentEnvironment always returns false.发生的问题是HostingEnvironment.IsDevelopmentEnvironment总是返回 false。

I tried to set it from the terminal with the ASPNETCORE_ENVIRONMENT=Development command and in the configuration setting of debug mode of my project with no luck.我尝试使用ASPNETCORE_ENVIRONMENT=Development命令从终端设置它,并且在我的项目的调试模式的配置设置中没有运气。 I can't find any solution to this problem.我找不到任何解决这个问题的方法。

// different script for dev or prod // dev 或 prod 的不同脚本

string scriptFileName = HostingEnvironment.IsDevelopmentEnvironment ? "/dist/app.entry.js" : "/dist/app.entry.min.js";

You're mixing up two things: ASP.NET vs. ASP.NET Core.您混淆了两件事:ASP.NET 与 ASP.NET Core。 The environment variable ASPNETCORE_ENVIRONMENT is used by ASP.NET Core, whereas the method HostingEnvironment.IsDevelopmentEnvironment is only part of old ASP.NET. ASP.NET Core 使用环境变量ASPNETCORE_ENVIRONMENT ,而HostingEnvironment.IsDevelopmentEnvironment方法只是旧 ASP.NET 的一部分。

As you already discovered, you have to set DEV_ENVIRONMENT=1 and I see two options:正如您已经发现的那样,您必须设置DEV_ENVIRONMENT=1并且我看到两个选项:

  1. Set environment variable system-wide在系统范围内设置环境变量
  2. Set environment variable within Rider configuration在 Rider 配置中设置环境变量

1. System-wide 1. 系统范围

This implies that all consumers (your app, integration tests, etc.) use the same value, ie all apps are in development mode.这意味着所有消费者(您的应用程序、集成测试等)都使用相同的值,即所有应用程序都处于开发模式。 It depends on your needs whether this is acceptable or not.这是否可以接受取决于您的需求。

Assuming that you're working on Windows, you can either set the environment variable via GUI ( see here ) or CLI ( see setx command ).假设您在 Windows 上工作,您可以通过 GUI( 请参阅此处)或 CLI( 请参阅setx命令)设置环境变量。

Keep in mind that environment variables are picked up on application startup.请记住,环境变量是在应用程序启动时获取的。 So you have to restart Rider after changing the variable.因此,您必须在更改变量后重新启动 Rider。

2. Rider 2. 骑士

Open the Run Configurations and configure it like this:打开运行配置并像这样配置它: 在此处输入图像描述 You have to do this for all your Run Configurations.您必须为所有运行配置执行此操作。

DEV_ENVIRONMENT=1添加到 JetBrains IDE 中的项目运行配置中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM