C# 你如何让T4ReferencePath工作?
在这件事上我已经碰壁好几天了。再多的谷歌搜索或胡闹似乎都不能给出答案 我想在构建时运行T4模板。在它中,我需要访问在此项目之前构建的程序集中的类型。我需要msbuild才能构建它,而msbuild不能很好地处理VS变量,因此我需要使用另一种方法来加载程序集 我在很多地方都读到T4ReferencePath是设置从中加载自定义程序集的位置的答案。然而,我无法让它工作 当我指定此项时:C# 你如何让T4ReferencePath工作?,c#,.net,msbuild,t4,C#,.net,Msbuild,T4,在这件事上我已经碰壁好几天了。再多的谷歌搜索或胡闹似乎都不能给出答案 我想在构建时运行T4模板。在它中,我需要访问在此项目之前构建的程序集中的类型。我需要msbuild才能构建它,而msbuild不能很好地处理VS变量,因此我需要使用另一种方法来加载程序集 我在很多地方都读到T4ReferencePath是设置从中加载自定义程序集的位置的答案。然而,我无法让它工作 当我指定此项时: <T4ReferencePath Include="$(TargetDir)" /> 当我尝试在
<T4ReferencePath Include="$(TargetDir)" />
当我尝试在VS中加载项目或使用msbuild运行项目时,会出现这种情况:
d:\Users\250894\Documents\Visual Studio 2013\Projects\TestT4\TestT4.csproj(90,22): error MSB4066: The attribute "Include" in element <T4ReferencePath> is unrecognized.
d:\Users\250894\Documents\Visual Studio 2013\Projects\TestT4\TestT4.csproj(90,22):错误MSB4066:无法识别元素中的属性“Include”。
我确实安装了“VisualStudio可视化和建模SDK”
我为缺乏简洁性而道歉,但我将包含我测试项目的整个.csproj文件,以防有明显的遗漏。我不包括我的.tt文件,因为如果我甚至无法加载我的csproj,它就不相关了。如果排除T4ReferencePath,则一切正常
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{5B9944E7-47CF-4BFE-BAEF-F02D29D59E80}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TestT4</RootNamespace>
<AssemblyName>TestT4</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Test.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Test.tt</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="Test.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Test.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<!-- Get the Visual Studio version – defaults to 12: -->
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">12.0</VisualStudioVersion>
<!-- Keep the next element all on one line: -->
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<TransformOnBuild>true</TransformOnBuild>
<IncludeDslT4Settings>true</IncludeDslT4Settings>
<T4ReferencePath Include="$(TargetDir)" />
</PropertyGroup>
<Import Project="$(VSToolsPath)\TextTemplating\Microsoft.TextTemplating.targets" />
</Project>
调试
任意CPU
{5B9944E7-47CF-4BFE-BAEF-F02D29D59E80}
Exe
性质
测试4
测试4
v4.5
512
任意CPU
真的
满的
假的
bin\Debug\
调试;痕迹
促使
4.
任意CPU
pdbonly
真的
bin\Release\
痕迹
促使
4.
真的
bin\x64\Debug\
调试;痕迹
满的
x64
促使
最小推荐规则集
真的
bin\x64\Release\
痕迹
真的
pdbonly
x64
促使
最小推荐规则集
真的
真的
真的
Test.tt
文本模板文件生成器
Test.cs
12
$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
真的
真的
我终于找到了答案。我无法想象以前没有人遇到过这种情况,但现在我们到了。希望,我已经开辟了一条道路,将帮助后面的人
不管常识告诉我什么,T4ReferencePath不是一个“属性”。这是一个“项目”。当我将它从“PropertyGroup”中删除并添加到“ItemGroup”中时,它很高兴
一般来说,软件开发和计算机使用的不利因素之一是无用的错误消息。我不能说这是我遇到过的最令人震惊的例子,但它就在上面。似乎无论我在最后发布问题之前花多长时间和精力寻找答案,我总是要么找到答案,要么自己解决。我不知道也不理解为什么,但T4ReferencePath不是一个属性。它是一个项目,因此它属于一个项目组。这对我来说没有任何意义,但项目文件至少现在加载了。对于未来的访问者,这是关于以下内容的MS文档: