gpt4 book ai didi

.net - 使用新的 csproj 格式 TransformXml?

转载 作者:行者123 更新时间:2023-12-02 04:18:14 25 4
gpt4 key购买 nike

我最近将一个解决方案从使用旧的 xml 格式的 csproj 文件升级为 xproj 被弃用后的新格式。即格式看起来像这样:

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<AssemblyName>MyProject</AssemblyName>
<PackageId>MyProject</PackageId>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
</PropertyGroup>
</Project>

问题是该解决方案包含大量已停止工作的 xml 转换。据我了解,这些转换是由 MyProject.wpp.targets 文件启动的。我自己还没有设置过这个,我对此也没有太多了解,但由于这个文件与旧的 csproj 文件格式相同,我猜这可能是它不起作用的原因,但我不这样做我不知道。非常感谢有关如何使其再次正常工作的任何帮助。

这就是 wpp.target 文件现在的样子

<?xml version="1.0" encoding="utf-8"?>

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="[MSBuild]\CommonConfigTransforms.xml"/>
<Import Project="[MSBuild]\BuildSpecificConfigTransforms.xml"/>
<Import Project="[MSBuild]\DeleteTempConfigFiles.xml"/>

<PropertyGroup>
<PrepareForBuildDependsOn>
$(PrepareForBuildDependsOn);
CommonConfigTransforms;
BuildSpecificConfigTransforms;
</PrepareForBuildDependsOn>
<BuildDependsOn>
$(BuildDependsOn);
DeleteTempConfigFiles
</BuildDependsOn>
</PropertyGroup>
</Project>

最佳答案

来自Migrating tasks from old csproj to new csproj format #2746 MSBuild 存储库的 GitHub 问题:

You have to change Target to be suitable with new approach (in this situation AfterTargets="PrepareForBuild") so the new part of csproj should looks like this:

<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="ApplyConfigurationConfigFile" AfterTargets="PrepareForBuild" Condition="Exists('App.$(Configuration).config')">
<ItemGroup>
<AppConfigWithTargetPath Remove="App.config" />
<AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
<TargetPath>$(TargetFileName).config</TargetPath>
</AppConfigWithTargetPath>
</ItemGroup>
<TransformXml Source="App.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="App.$(Configuration).config" />
</Target>

关于.net - 使用新的 csproj 格式 TransformXml?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47312487/

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