English 中文(简体)
VS和Rier无视源生成者生成的文件
原标题:VS and Rider ignore source generator generated files
  • 时间:2023-05-21 02:48:40
  •  标签:

C# 来源生成的档案被忽略,或显示错误,但当我复制档案时,所有材料都投入使用。

国家。 案文.g.c

using System.Collections.Generic;
using System.Linq;

#nullable enable
namespace GeneratorUnitTestProject.StateMachineTests
{
//[...]
}

它说,错误是预期的CS1001 Identifier。

如果我复制所生成的档案并去除发电机,那么它就非常精干,我的股测试会成功。

这是我单位试验解决办法的主轴。

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>net7.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
    
        <IsPackable>false</IsPackable>
        <IsTestProject>true</IsTestProject>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
        <PackageReference Include="NUnit" Version="3.13.3" />
        <PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
        <PackageReference Include="NUnit.Analyzers" Version="3.6.1" />
        <PackageReference Include="coverlet.collector" Version="3.2.0" />
        <ProjectReference Include="..TaskReward.ExpanderTaskReward.Expander.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
    </ItemGroup>

    <ItemGroup>
      <AdditionalFiles Include="StateMachineTestsText.xstate" />
    </ItemGroup>

</Project>

这也是我的发电机的产物。

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <LangVersion>Latest</LangVersion>
    <Nullable>enable</Nullable>
    <EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" PrivateAssets="all" />
    <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.6.0" PrivateAssets="all" />
  </ItemGroup>

  <ItemGroup>
    <!-- Generator dependencies -->
    <PackageReference Include="Newtonsoft.Json" Version="12.0.2" PrivateAssets="all" GeneratePathProperty="True" />
  </ItemGroup>

  <PropertyGroup>
    <GetTargetPathDependsOn>$(GetTargetPathDependsOn);GetDependencyTargetPaths</GetTargetPathDependsOn>
  </PropertyGroup>

  <Target Name="GetDependencyTargetPaths">
    <ItemGroup>
      <TargetPathWithTargetPlatformMoniker Include="$(PKGNewtonsoft_Json)lib
etstandard2.0Newtonsoft.Json.dll" IncludeRuntimeDependency="false" />
      <!-- Pack both our DLL and the dependencies into a generated Nuget Package -->
      <None Include="$(OutputPath)$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
      <None Include="$(PKGNewtonsoft_Json)lib
etstandard2.0Newtonsoft.Json.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
    </ItemGroup>
  </Target>

</Project>

If I go ahead and add a "gen." infront of the namespace the error changes to namespace not found. (CS0246) But the IDE (Rider or VS) dont show any error in the UI. Its like it gets ignored but the error Log doesnt say anything about it.

Fehler beim Buildvorgang.

       "...GeneratorUnitTestProjectGeneratorUnitTestProject.csproj" (build Ziel) (1) ->
       (CoreCompile Ziel) -> 
         ...GeneratorUnitTestProject.......Gen.State.Statemachines国家。 案文.g.c(172,106): warning CS8669: Die Anmerkung für Nullable-Verweistypen darf nur in Code innerhalb eines #nullable-Anmerkungskontexts verwendet werden. Für automatisch generierten Code ist eine explizite #nullable-Anweisung in der Quelle erforderlich.


       "...GeneratorUnitTestProjectGeneratorUnitTestProject.csproj" (build Ziel) (1) ->
       (CoreCompile Ziel) -> 
         ...GeneratorUnitTestProjectStateMachineTestsMachineTest.cs(1,7): error CS0246: Der Typ- oder Namespacename "gen" wurde nicht gefunden (möglicherweise fehlt eine using-Direktive oder ein Assemblyverweis).

    1 Warnung(en)
    1 Fehler
问题回答

暂无回答




相关问题
热门标签