Webプロジェクトで.ttファイルをコンパイルする前にビルドシステムが更新するURLをweb.configファイルに入力しようとしています。.ttファイル(T4テンプレート)からweb.configからappSettingを読み取るにはどうすればいいですか?
私の.ttファイルから関連するセクションは以下の通りです:
<#@ template debug="true" hostSpecific="true" language="C#" #>
<#@ output extension=".ts" #>
<#@ Assembly Name="System.Core.dll" #>
<#@ Assembly Name="System.Configuration.dll" #>
<#@ import namespace="System" #>
<#@ import namespace="System.Reflection" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Configuration" #>
<#@ import namespace="System.Collections.Specialized" #>
import { Injectable } from "@angular/core";
<#= RegisterNameSpace("Server.Web.Dashboard.Models.APIRequest") #>
<#= RegisterNameSpace("Server.Web.Dashboard.Models.APIResponse") #>
<#= RegisterNameSpace("Server.Web.Dashboard.Models.APIGeneric") #>
<#= RegisterNameSpace("Server.Data.POCODataObjects") #>
@Injectable()
export class WebServiceCommunicatorService {
rootUrl : string = '<#= ConfigurationManager.AppSettings["ServerServiceURL"] #>';
.....
私は.ttファイルから.TSファイルを生成しようとすると、私は次のようなエラーメッセージが出ます:
Severity Code Description Project File Line Suppression State
Error An expression block evaluated as Null
System.ArgumentNullException: Value cannot be null.
Parameter name: objectToConvert
at Microsoft.VisualStudio.TextTemplating.ToStringHelper.ToStringWithCulture(Object objectToConvert)
at Microsoft.VisualStudio.TextTemplatingF553823B88CD6076D80EB08F6EA809752D0E5DC3E61C0FA53FB2F9AC22ACABF3B7BB9C8801A54E5DBC2A556C03FA42F2EA2AFCE58B708BEC94B0968193987868.GeneratedTextTransformation.TransformText() in webservicecommunicator.service.tt:line 35 Dashboard webservicecommunicator.service.tt 35
私がこれまでにweb.configファイルのパスを見つけることができた:文字列absolutePath = this.Host.ResolvePath( "../../../web.config"); – user230910
私はあなたのソリューションを試しましたが、それは動作しません、私はそれがどこにでもC:\ ProgramFilesの現在のディレクトリにあると考えられる場所にいくつかの制限があると思います – user230910