TextTransformation.exe(ILSpy)のソースコードを見ると、これはテンプレートを変更しなければ可能ではないと思いますが(解決方法はあります)
は最終的に私たちがここで気に何Microsoft.VisualStudio.TextTemplating.Engine.ResolveAssemblyReferencesは()が呼び出されたテンプレートの解析時の段階です。 ITextTemplatingEngineHost.ResolveAssemblyReference()(それが最初の環境変数を展開するんが)
テンプレートは、コマンドラインから実行された場合、使用中の実装は単にCommandLineHost、およびその実装が提供することにあるこの代表団参照パスとGACで提供されているファイルを探します。ファイル名にはまだこの時点で$(SolutionPath)ビットが入っていますので、決して成功することはありません。
CommandLineHostが内部:-(であるか、あなたが潜在的にモノポートhttps://stackoverflow.com/a/1395377/26167
を活用する可能性があるので、あなたがTextTransform.exeのご
自身バージョンを実装することができますが、あなたはスクラッチ(または使用リフレクション)から大きく起動する必要があるだろう
私は同じ船に乗って自分自身を見つけるので、私は、このことについて満足していると言うことはできません...
編集:しかし...最終的にあなたがする必要があるすべては、テンプレートを変更であることから、 PowerShellスクリプトを使ってテンプレートをtempディレクトリにコピーし、手動で$(SolutionDir)maを展開してプロセスの中でcroを実行し、そこから実行します。それはちょうど良いを動作するようです。
問題のあるプロジェクトにドロップこれを(あなたは、ファイルの拡張子を変更したい場合があります)、あなたが行くように良いことがあります:
<#
.Synopsis
Executes all the T4 templates within designated areas of the containing project
.Description
Unfortunately the Visual Studio 2010 'Transform All Templates' function doesn't appear
to work in SSDT projects, so have to resort to hackery like this to bulk-execute templates
#>
param(
)
$ErrorActionPreference = 'stop';
$scriptDir = Split-Path $MyInvocation.MyCommand.Path
$commonProgramFiles32 = $env:CommmonProgramFiles
if (Test-Path environment::"CommonProgramFiles(x86)") { $commonProgramFiles32 = (gi "Env:CommonProgramFiles(x86)").Value };
$t4 = Resolve-Path "$commonProgramFiles32\Microsoft Shared\TextTemplating\10.0\texttransform.exe";
$solutionDir = Resolve-Path "$scriptDir\..\"
$templates = @(dir "$scriptDir\Database Objects\load\*.tt")
# Cloning to temp dir originally caused issues, because I use the file name in the template (doh!)
# Now I copy to temp dir under the same name
pushd $scriptDir;
try{
foreach($template in $templates){
$templateTemp = Join-Path ([IO.Path]::GetTempPath()) $template.Name;
$targetfile = [IO.Path]::ChangeExtension($template.FullName, '.sql');
Write-Host "Running $($template.Name)"
Write-Host "...output to $targetFile";
# When run from outside VisualStudio you can't use $(SolutionDir)
# ...so have to modify the template to get this to work...
# ...do this by cloning to a temp file, and running this instead
Get-Content $template.FullName | % {
$_.Replace('$(SolutionDir)',"$solutionDir")
} | Out-File -FilePath:$templateTemp
try{
& $t4 $templateTemp -out $targetfile -I $template.DirectoryName;
}finally{
if(Test-Path $templateTemp){ Remove-Item $templateTemp; }
}
}
}finally{
popd;
}
を使用すると、現在のディレクトリに変数を設定するには、 '設定SolutionDirは=%でcd%'を試したことがありますか? – Pawel
それは動作しません、どちらも-a !! $(SolutionDir)!C:\ dev \ mysolutionroot – piers7
T4のMonoポートがあります。私は答えがどこかのコードベースにあるのだろうかと思います。 http://stackoverflow.com/a/1395377/26167を参照してください。 – piers7