gpt4 book ai didi

c# - 如何让 T4ReferencePath 工作?

转载 作者:太空狗 更新时间:2023-10-30 01:19:10 27 4
gpt4 key购买 nike

为了这个,我已经用头撞墙好几天了。谷歌搜索或四处乱逛似乎都找不到答案。

我想在构建时运行 T4 模板。在其中,我需要访问我在此项目之前构建的程序集中的类型。我需要 msbuild 才能构建它,而 msbuild 不能很好地处理 VS 变量,因此我需要使用另一种方法来加载程序集。

我在很多地方都读到 T4ReferencePath 是设置从中加载自定义程序集的地方的答案。但是,我无法让它工作。

当我指定这个时:

<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.

我确实安装了“Visual Studio 可视化和建模 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>

最佳答案

我终于偶然发现了答案。我无法想象以前没有人遇到过这种情况,但我们就是这样。希望我开辟了一条道路,可以帮助后来者。

尽管常识告诉我,T4ReferencePath 不是“属性”。这是一个“项目”。当我将它从“PropertyGroup”中删除并将其添加到“ItemGroup”时,它很高兴。

一般而言,软件开发和计算机使用的缺陷之一是无用的错误消息。我不能说这是我遇到过的最恶劣的例子,但它就在那里。

关于c# - 如何让 T4ReferencePath 工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24129515/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com