英文:
Don't include all @page for a certain configuration within Blazor Server app
问题
有没有办法我可以控制何时在 Blazor 服务器应用程序中添加 @page 指令?
例如,假设我只希望页面 /Test 在 DEBUG 配置中包含,而不在 release 中包含。
我已经尝试在 .razor 文件中使用 #define 指定编译器指令。
英文:
Is there anyway I can controll when to add a @page directive within a Blazor server app?
For example lets say I want the page /Test only be included within DEBUG configuration but not in release.
I've already tried specifying compilere directives with #define within the .razor file.
答案1
得分: 2
I've already tried specifying compilere directives with #define within the .razor file.
And that won't work. But you can apply #if in a .razor.cs file. So you need to create the code behind file first. (type Ctrl+. on the @code tag)
And then:
#if DEBUG
    [RouteAttribute("/fetchdata")]
#endif
    public partial class FetchData
    { 
       ...
@page("<path>") becomes [RouteAttribute("<path>")]
英文:
> I've already tried specifying compilere directives with #define within the .razor file.
And that won't work. But you can apply #if in a .razor.cs file. So you need to create the code behind file first. (type Ctrl+. on the @code tag)
And then:
#if DEBUG
    [RouteAttribute("/fetchdata")]
#endif
    public partial class FetchData
    { 
       ...
@page("<path>") becomes     [RouteAttribute("<path>")]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论