【发布时间】:2021-08-07 18:06:52
【问题描述】:
我们有多个存储库,每个存储库都有自己的 .editorconfig。显然,这些没有同步,这就是为什么我想通过 NuGet 包将 .editorconfig 从我们的框架解决方案(连同其他文件)分发到我们所有的存储库/解决方案,并通过简单的复制构建任务将其复制到解决方案目录.
我尝试执行以下操作:
创建一个项目“EditorConfigDistribution”,它应该包含主 .editorconfig 文件。
<Project Sdk="Microsoft.NET.Sdk">
...
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<NoDefaultExcludes>true</NoDefaultExcludes>
</PropertyGroup>
<ItemGroup>
<Content Include=".editorconfig">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>true</Pack>
<PackageCopyToOutput>false</PackageCopyToOutput>
<PackagePath>contentFiles\any\any\content</PackagePath>
</Content>
</ItemGroup>
</Project>
这一切都按预期工作,我确实从其他解决方案中获得了我项目中所需的 .editorconfig 文件,它在文件夹 content/.editorconfig 中被引用为快捷方式(请参阅EditorConfigConsumer Project Structure)。
该文件只是对C:\Users\<user>\.nuget\packages\editorconfigdistribution\1.0.0\contentFiles\any\any\content\.editorconfig的引用。
现在,我想通过构建任务复制那个 .editorconfig 文件:
<Project Sdk="Microsoft.NET.Sdk">
...
<ItemGroup>
<PackageReference Include="EditorConfigDistribution" Version="1.0.0">
</PackageReference>
</ItemGroup>
<Target Name="CopyEditorConfig" BeforeTargets="BeforeBuild">
<ItemGroup>
<EditorConfigFileToCopy Include="$(MSBuildProjectDirectory)\content\.editorconfig" />
</ItemGroup>
<Copy SourceFiles="@(EditorConfigFileToCopy)" DestinationFolder="$(MSBuildProjectDirectory)\.." SkipUnchangedFiles="true" UseHardlinksIfPossible="false" />
</Target>
</Project>
但是,我确实收到以下错误:
Error MSB3030: Could not copy the file "C:\Users\weberma9\source\repos\<some_path>\EditorConfigConsumer\content\.editorconfig" because it was not found. (20, 5)
我可以理解无法找到该文件(因为它是一个快捷方式),但我只是想不出在我的构建任务中正确引用该快捷方式的方法。
我需要在<EditorConfigFileToCopy Include="$(MSBuildProjectDirectory)\content\.editorconfig" /> 的那一行更改什么?
当然,如果您对我的一般问题有更好的方法 - 我很高兴听到。
【问题讨论】:
标签: msbuild nuget .net-standard editorconfig