Microsoft Build Engine,也称为MSBuild,是托管代码的构建平台,是.NET Framework的一部分。
当<Compile>和<EmbeddedResource>之外的文件发生更改时,如何避免 Visual Studio 增量构建无法运行?
我有一个 VS2017 csharp 项目,.csproj 文件如下所示: 执行 我有一个 VS2017 csharp 项目,.csproj 文件如下所示: <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp2.0</TargetFramework> </PropertyGroup> <ItemGroup> <MyItem Include="file.dat" /> </ItemGroup> <PropertyGroup> <PrepareResourcesDependsOn> $(PrepareResourcesDependsOn); MyCompileTarget </PrepareResourcesDependsOn> <CoreCompileDependsOn> $(CoreCompileDependsOn); MyCompileTarget </CoreCompileDependsOn> </PropertyGroup> <Target Name="MyCompileTarget" Inputs="@(MyItem)" Outputs="@(MyItem->'%(FileName).out')"> ... </Target> </Project> 其中 MyCompileTarget 是从 file.out 生成 file.dat 的目标(在实际代码中,增量构建目标和属性位于通过 NuGet 包自动包含的目标文件中)。 问题是,如果我更改 file.dat 并按 Build,则根本不会执行 目标(但 MyTarget 使用 Rebuild 或使用 msbuild 运行时可以正确执行)。我希望执行 MyCompileTarget 以便更新 file.out 文件。 如果我使用 BeforeBuild 或 AfterBuild 而不是 PrepareResourcesDependsOn 等,也会出现同样的问题 除非 @(Compile) 或 @(EmbeddedResource) 中的某些文件发生更改,否则 Visual Studio 增量构建似乎不会启动。事实上,如果我添加以下内容 <EmbeddedResource>file.dat</EmbeddedResource> 增量构建按预期工作(但显然我不想将 file.dat 嵌入到生成的程序集中)。 如果修改了file.dat,并且相应的生成文件早于file.dat或不存在,是否可以强制Visual Studio启用增量构建? 注意:使用 VS2015、.NET CORE 或 .NET FRAMEWORK 也会出现同样的问题。 另外,如果我更改 csharp 文件,将触发增量构建,因此它将触发 MyTask,但前提是 file.dat 比生成的文件更新(如预期)。 提前致谢, 法比奥。 如果 file.dat 被修改,是否可以强制 Visual Studio 启用增量构建 您可以在项目文件中将属性 DisableFastUpToDateCheck 设置为 true,以禁用 Visual Studio 构建管理器的 FastUpToDateCheck: <PropertyGroup> <DisableFastUpToDateCheck>True</DisableFastUpToDateCheck> </PropertyGroup> 检查MSDN有关DisableFastUpToDateCheck的信息: 仅适用于 Visual Studio 的布尔值。 视觉工作室 构建管理器使用名为 FastUpToDateCheck 的过程来确定 是否必须重建项目才能保持最新状态。 此过程是 比使用 MSBuild 更快地确定这一点。 设置 将 DisableFastUpToDateCheck 属性设置为 true 可让您绕过 Visual Studio 构建管理器并强制它使用 MSBuild 来确定是否 该项目是最新的 更新: 此外,我们还可以将 UpToDateCheckInput 设置为项目: <UpToDateCheckInput Include="file.dat" /> 禁用 VS 快速更新检查会让你的构建速度变慢。别这样做! 相反,请确保最新检查了解项目中的项目以及它们与构建的关系。为此,您可以将两种项目添加到您的项目中: UpToDateCheckInput 用于输入 UpToDateCheckBuilt 用于输出 在您的情况下,您需要第二个选项,因为既有输入又有输出。您需要确保如果删除输出,它会被重建。 <ItemGroup> <UpToDateCheckBuilt Original="@(MyItem)" Include="@(MyItem->'%(FileName).out')"> </ItemGroup> 有关更多信息,请参阅文档: https://github.com/dotnet/project-system/blob/main/docs/up-to-date-check.md
MSBuild 允许您使用 -target: 指定构建目标,例如 Build 或 Clean(示例:MSBuild.exe -target:Clean)。 当然,开发人员可以使用 .
为什么 Visual Studio 不在输出窗口中显示项目/目标性能摘要?
如果我在 Visual Studio 2022 中构建一个简单的 .NET 8.0 HelloWorld 项目,我会在输出窗口中得到以下输出: 重建于 14:53 开始... 1>------ 重建全部开始:项目:HelloWor...
嗨,我对 MSBuild 还很陌生,所以任何反馈都非常有帮助。我正在尝试执行一个构建步骤来编译任何 *.less 文件以与 Blazor 一起使用。我以前使用过 WebCompiler 但它不...
在 Mac 上调试 .NET 8 iOS 应用程序(包括其扩展)的现代方法是什么?
本题有两个相关问题: 1. 在 Mac 上调试 .NET 8+ 应用程序的现代方法是什么? 出现这个问题的原因是: VS for Mac 即将退役(2024 年 5 月),即使现在它......
在 msbuild 条件下针对 .net5 或更高版本的所有 .Net 版本
构建具有多个目标框架 .Net 6.0 和 .Net Framework 4.7.2 (net6.0;net472) 应用程序的应用程序时,您可以指定条件...
我有一个目标作为我的构建的一部分,我希望在评估某些命令行检查时跳过它: ....
我有一个C++库,它被编译为动态库和静态库。最近我将资源版本文件添加到源中。动态库编译工作正常,但静态库编译明星......
我有一个 VS10 项目文件(.csproj)。我正在从命令行使用 MSBuild 构建这个项目。我有一个简单的问题,我长期以来一直试图弄清楚。有什么不同...
如何使用 Windows SDK 7.1 从命令行运行 msbuild?
我正在我们的 CI 服务器上设置 .NET 4.0 支持。我已经安装了 .NET 4.0 和 Windows 7.1 SDK 中的 .NET 工具。 在 .NET 2.0 和 3.5 上,这一切都有效。使用 .NET 4,当我运行“Windows ...
如何使用 MSBuild NuGet 将 .csproj 文件加载到 .NET Core 3.0 中
我有一个非常简单的控制台项目: 班级计划 { 静态无效主(字符串[]参数) { var 项目 = 新项目( “FishStory.csproj”, 无效的, 不...
nupkg“Microsoft.Build”中的“内部 MSBuild 错误”
我正在尝试使用 Microsoft.Build nuget 包来: 打开解决方案 枚举其中的项目 发现创建的 DLL。 故障模式似乎超级丰富,我错了……
Visual Studio 2022 - 嵌套部分类(文件)
我注意到,在我的解决方案中,嵌套部分类仅适用于 Microsoft.NET.Sdk.Web 项目。 对于其余项目(Microsoft.NET.Sdk),它不起作用。 有谁知道吗...
我有一个简单的 C# 项目,其中包含以下 .csproj 文件: net8.0 我有一个简单的 C# 项目,包含以下 .csproj 文件: <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net8.0</TargetFramework> <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks> <UseMaui>true</UseMaui> <SingleProject>true</SingleProject> <ImplicitUsings>enable</ImplicitUsings> </PropertyGroup> <PropertyGroup> <EnableDefaultCompileItems>true</EnableDefaultCompileItems> </PropertyGroup> <ItemGroup> <PackageReference Include="CrcDotNET" Version="1.0.3" /> <PackageReference Include="System.IO.Ports" Version="8.0.0" /> <PackageReference Include="System.Threading.Tasks" Version="4.3.0" /> </ItemGroup> </Project> 当我尝试使用“dotnet build Foo.csproj”在 localdev 上构建它时,一切都可以正常工作。但是当我在 Azure 上使用相同的命令时,我收到以下神秘错误: 2024-02-22T12:23:29.8030466Z ##[section]Starting: Build and Pack 'Laeerdal.Usb.csproj' 2024-02-22T12:23:29.8150494Z ============================================================================== 2024-02-22T12:23:29.8151277Z Task : .NET Core 2024-02-22T12:23:29.8151536Z Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command 2024-02-22T12:23:29.8151870Z Version : 2.235.0 2024-02-22T12:23:29.8152112Z Author : Microsoft Corporation 2024-02-22T12:23:29.8152370Z Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli 2024-02-22T12:23:29.8152667Z ============================================================================== 2024-02-22T12:23:30.2857118Z [command]C:\Windows\system32\chcp.com 65001 2024-02-22T12:23:30.2964423Z Active code page: 65001 2024-02-22T12:23:30.3088676Z Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version. 2024-02-22T12:23:30.3142054Z [command]"C:\Program Files\dotnet\dotnet.exe" build D:\a\1\s\Foo\Foo.csproj "-dl:CentralLogger,\"D:\a\_tasks\DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b\2.235.0\dotnet-build-helpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll\"*ForwardingLogger,\"D:\a\_tasks\DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b\2.235.0\dotnet-build-helpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll\"" /restore /p:PackageOutputPath=D:\a\1\a /p:JavaSdkDirectory=C:\hostedtoolcache\windows\Java_Temurin-Hotspot_jdk\8.0.402-6\x64/ /p:VersionMajor=1 /p:VersionMinor=30 /p:VersionPatch=2 /p:VersionRevision=50224 /p:VersionSuffix= 2024-02-22T12:23:30.4882178Z MSBuild version 17.9.4+90725d08d for .NET 2024-02-22T12:23:31.3250928Z Determining projects to restore... 2024-02-22T12:23:31.5489970Z ##[warning]C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\8.0.6\Sdk\BundledVersions.targets(85,5): Warning MA002: Starting with .NET 8, setting <UseMaui>true</UseMaui> does not automatically include NuGet package references in your project. Update your project by including this item: <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.6" />. You can skip this warning by setting <SkipValidateMauiImplicitPackageReferences>true</SkipValidateMauiImplicitPackageReferences> in your project file. 2024-02-22T12:23:31.5529575Z C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\8.0.6\Sdk\BundledVersions.targets(85,5): warning MA002: Starting with .NET 8, setting <UseMaui>true</UseMaui> does not automatically include NuGet package references in your project. Update your project by including this item: <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.6" />. You can skip this warning by setting <SkipValidateMauiImplicitPackageReferences>true</SkipValidateMauiImplicitPackageReferences> in your project file. [D:\a\1\s\Foo\Foo.csproj::TargetFramework=net8.0] 2024-02-22T12:23:31.6426560Z ##[warning]C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\8.0.6\Sdk\BundledVersions.targets(85,5): Warning MA002: Starting with .NET 8, setting <UseMaui>true</UseMaui> does not automatically include NuGet package references in your project. Update your project by including this item: <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.6" />. You can skip this warning by setting <SkipValidateMauiImplicitPackageReferences>true</SkipValidateMauiImplicitPackageReferences> in your project file. 2024-02-22T12:23:31.6431641Z C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\8.0.6\Sdk\BundledVersions.targets(85,5): warning MA002: Starting with .NET 8, setting <UseMaui>true</UseMaui> does not automatically include NuGet package references in your project. Update your project by including this item: <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.6" />. You can skip this warning by setting <SkipValidateMauiImplicitPackageReferences>true</SkipValidateMauiImplicitPackageReferences> in your project file. [D:\a\1\s\Foo\Foo.csproj::TargetFramework=net8.0-windows10.0.19041.0] 2024-02-22T12:23:32.5074255Z Restored D:\a\1\s\Foo\Foo.csproj (in 702 ms). 2024-02-22T12:23:37.4168585Z ##[warning]C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\8.0.6\Sdk\BundledVersions.targets(85,5): Warning MA002: Starting with .NET 8, setting <UseMaui>true</UseMaui> does not automatically include NuGet package references in your project. Update your project by including this item: <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.6" />. You can skip this warning by setting <SkipValidateMauiImplicitPackageReferences>true</SkipValidateMauiImplicitPackageReferences> in your project file. 2024-02-22T12:23:37.4173672Z C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\8.0.6\Sdk\BundledVersions.targets(85,5): warning MA002: Starting with .NET 8, setting <UseMaui>true</UseMaui> does not automatically include NuGet package references in your project. Update your project by including this item: <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.6" />. You can skip this warning by setting <SkipValidateMauiImplicitPackageReferences>true</SkipValidateMauiImplicitPackageReferences> in your project file. [D:\a\1\s\Foo\Foo.csproj::TargetFramework=net8.0] 2024-02-22T12:23:37.6003354Z ##[error]C:\Program Files\dotnet\sdk\8.0.200\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): Error NETSDK1005: Assets file 'D:\a\1\s\Foo\obj\project.assets.json' doesn't have a target for 'net8.0'. Ensure that restore has run and that you have included 'net8.0' in the TargetFrameworks for your project. 2024-02-22T12:23:37.6025309Z C:\Program Files\dotnet\sdk\8.0.200\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error NETSDK1005: Assets file 'D:\a\1\s\Foo\obj\project.assets.json' doesn't have a target for 'net8.0'. Ensure that restore has run and that you have included 'net8.0' in the TargetFrameworks for your project. [D:\a\1\s\Foo\Foo.csproj::TargetFramework=net8.0] 2024-02-22T12:23:37.9060631Z 2024-02-22T12:23:37.9092458Z Build FAILED. 2024-02-22T12:23:37.9172096Z 2024-02-22T12:23:37.9242343Z C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\8.0.6\Sdk\BundledVersions.targets(85,5): warning MA002: Starting with .NET 8, setting <UseMaui>true</UseMaui> does not automatically include NuGet package references in your project. Update your project by including this item: <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.6" />. You can skip this warning by setting <SkipValidateMauiImplicitPackageReferences>true</SkipValidateMauiImplicitPackageReferences> in your project file. [D:\a\1\s\Foo\Foo.csproj::TargetFramework=net8.0] 2024-02-22T12:23:37.9327192Z C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\8.0.6\Sdk\BundledVersions.targets(85,5): warning MA002: Starting with .NET 8, setting <UseMaui>true</UseMaui> does not automatically include NuGet package references in your project. Update your project by including this item: <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.6" />. You can skip this warning by setting <SkipValidateMauiImplicitPackageReferences>true</SkipValidateMauiImplicitPackageReferences> in your project file. [D:\a\1\s\Foo\Foo.csproj::TargetFramework=net8.0-windows10.0.19041.0] 2024-02-22T12:23:37.9343030Z C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\8.0.6\Sdk\BundledVersions.targets(85,5): warning MA002: Starting with .NET 8, setting <UseMaui>true</UseMaui> does not automatically include NuGet package references in your project. Update your project by including this item: <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.6" />. You can skip this warning by setting <SkipValidateMauiImplicitPackageReferences>true</SkipValidateMauiImplicitPackageReferences> in your project file. [D:\a\1\s\Foo\Foo.csproj::TargetFramework=net8.0] 2024-02-22T12:23:37.9348329Z C:\Program Files\dotnet\sdk\8.0.200\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error NETSDK1005: Assets file 'D:\a\1\s\Foo\obj\project.assets.json' doesn't have a target for 'net8.0'. Ensure that restore has run and that you have included 'net8.0' in the TargetFrameworks for your project. [D:\a\1\s\Foo\Foo.csproj::TargetFramework=net8.0] 2024-02-22T12:23:37.9349813Z 3 Warning(s) 2024-02-22T12:23:37.9350763Z 1 Error(s) 2024-02-22T12:23:37.9352937Z 2024-02-22T12:23:37.9385231Z Time Elapsed 00:00:07.20 2024-02-22T12:23:39.2936283Z ##[error]Error: The process 'C:\Program Files\dotnet\dotnet.exe' failed with exit code 1 2024-02-22T12:23:39.2939954Z ##[warning].NET 5 has some compatibility issues with older Nuget versions(<=5.7), so if you are using an older Nuget version(and not dotnet cli) to restore, then the dotnet cli commands (e.g. dotnet build) which rely on such restored packages might fail. To mitigate such error, you can either: (1) - Use dotnet cli to restore, (2) - Use Nuget version 5.8 to restore, (3) - Use global.json using an older sdk version(<=3) to build 2024-02-22T12:23:39.2961848Z Info: Azure Pipelines hosted agents have been updated and now contain .Net 5.x SDK/Runtime along with the older .Net Core version which are currently lts. Unless you have locked down a SDK version for your project(s), 5.x SDK might be picked up which might have breaking behavior as compared to previous versions. You can learn more about the breaking changes here: https://docs.microsoft.com/en-us/dotnet/core/tools/ and https://docs.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting 2024-02-22T12:23:39.2963921Z ##[error]Dotnet command failed with non-zero exit code on the following projects : [ 'D:\\a\\1\\s\\Foo\\Foo.csproj' ] 2024-02-22T12:23:39.3057978Z ##[section]Finishing: Build and Pack 'Laeerdal.Usb.csproj' (并回答我自己的问题...)错误是我正在使用: <TargetFramework>net8.0</TargetFramework> 虽然我应该使用: <TargetFrameworks>net8.0</TargetFrameworks> 构建在 localdev 上运行的原因是我的 localdev 在 MacOS 上运行,而 Azure 中的管道在 Windows 上运行,就此而言,构建也将针对 net8.0 之上的 net8.0-windows10.0.19041.0 依次进行堵塞的 msbuild 导致上面提到的神秘错误。 希望这可以帮助某人避免因为问题而用头撞墙的两天。
如何在 Azure Devops 中使用 WIX 创建 .msi 安装程序?
我正在尝试使用 yaml 脚本在 azure devops 中为我的 dektop 应用程序创建一个带有 wix 的 .msi 安装程序包。下面是为此创建的 msbuild 任务: - 任务:MSBuild@1 输入: 解决方案...
如何使 .NET Core MSBuild 不为元包项目生成空程序集
我有一个在project.json 中定义的.NET Core 元包项目。它不包含任何代码,仅包含对其他一些子项目的引用。这个元包项目的存在有两个目的: NuGet 元-
我正在为外部 C++ 库编写一个 .NET 绑定项目。想要将该库包含到 nupkg 文件中,因此用户只需安装该包即可使用它。图书馆就是平台
我的 Azure-pipiline 失败,并显示消息“.NET SDK 版本 8.0.101 需要至少 17.7.0 版本的 MSBuild”
我遇到了此 Azure 管道的问题: 扳机: - 一体化 水池: vmImage:'Ubuntu-22.04' 变量: 构建配置:“发布” 阶段: - 阶段:持续集成 工作...
我正在尝试获取每个编译单元的编译参数,以便我可以为我的 vcxproj 创建可与 clang 的 libTooling 一起使用的“compilation_commands.json”。 libTooling 教程