msbuild 相关问题

Microsoft Build Engine,也称为MSBuild,是托管代码的构建平台,是.NET Framework的一部分。

如何正确编写批处理文件以供发布在.NET编程过程中添加不同的预编译宏?

我有以下代码: #如果是电脑 var rootPath = Path.Combine("dist"); #别的 var rootPath = Path.Combine(@"/bin/bash"); #万一 我想在

回答 1 投票 0

.pubxml 中的 MsBuild DefineConstants 无法正常工作

我有 ASP.NET Core + Blazor 应用程序(默认模板)和 2 个项目。 当我创建 IIS 发布配置文件时:

回答 0 投票 0

MSBuild - 根据具体情况引入PackageReference

这个想法是,如果 BuildConfigurations 元数据中未指定活动/当前构建配置,则将引用的项目作为包拉取。否则它将被添加为 ProjectReference。在...

回答 1 投票 0

如何在您的家用电脑上成功构建从 GitHub 下载的 Microsoft.Dotnet.Wpf.sln 存储库?

我正在尝试构建一个从 GitHub 下载的 Microsoft.Dotnet.Wpf.sln。我按照说明中所述安装了 Visual Studio 2022 Preview。现在,当我打开 Microsoft.Dotnet.Wpf...

回答 1 投票 0

dotnet 发布配置文件忽略 pubxml 文件

我有以下通过 Visual Studio 2019 创建的 pubxml 文件: <

回答 4 投票 0

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

回答 2 投票 0

MSBuild 的现有构建目标是什么?

MSBuild 允许您使用 -target: 指定构建目标,例如 Build 或 Clean(示例:MSBuild.exe -target:Clean)。 当然,开发人员可以使用 .

回答 2 投票 0

我可以将编译常量传递给项目引用吗?

如果我有 引用,有什么方法可以将条件编译值传递给该项目吗?像这样的东西(我知道不存在这样的...

回答 4 投票 0

为什么 Visual Studio 不在输出窗口中显示项目/目标性能摘要?

如果我在 Visual Studio 2022 中构建一个简单的 .NET 8.0 HelloWorld 项目,我会在输出窗口中得到以下输出: 重建于 14:53 开始... 1>------ 重建全部开始:项目:HelloWor...

回答 1 投票 0

如何让 MSBuild 目标在输入文件更改时运行?

嗨,我对 MSBuild 还很陌生,所以任何反馈都非常有帮助。我正在尝试执行一个构建步骤来编译任何 *.less 文件以与 Blazor 一起使用。我以前使用过 WebCompiler 但它不...

回答 1 投票 0

在 Mac 上调试 .NET 8 iOS 应用程序(包括其扩展)的现代方法是什么?

本题有两个相关问题: 1. 在 Mac 上调试 .NET 8+ 应用程序的现代方法是什么? 出现这个问题的原因是: VS for Mac 即将退役(2024 年 5 月),即使现在它......

回答 1 投票 0

在 msbuild 条件下针对 .net5 或更高版本的所有 .Net 版本

构建具有多个目标框架 .Net 6.0 和 .Net Framework 4.7.2 (net6.0;net472) 应用程序的应用程序时,您可以指定条件...

回答 2 投票 0

如何从命令行传递 msbuild 条件?

我有一个目标作为我的构建的一部分,我希望在评估某些命令行检查时跳过它: ....

回答 2 投票 0

msbuild - 将资源文件添加到项目后静态库编译失败

我有一个C++库,它被编译为动态库和静态库。最近我将资源版本文件添加到源中。动态库编译工作正常,但静态库编译明星......

回答 2 投票 0

MSBuild 指定/未指定平台参数时的差异

我有一个 VS10 项目文件(.csproj)。我正在从命令行使用 MSBuild 构建这个项目。我有一个简单的问题,我长期以来一直试图弄清楚。有什么不同...

回答 1 投票 0

如何使用 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 ...

回答 10 投票 0

如何使用 MSBuild NuGet 将 .csproj 文件加载到 .NET Core 3.0 中

我有一个非常简单的控制台项目: 班级计划 { 静态无效主(字符串[]参数) { var 项目 = 新项目( “FishStory.csproj”, 无效的, 不...

回答 3 投票 0

nupkg“Microsoft.Build”中的“内部 MSBuild 错误”

我正在尝试使用 Microsoft.Build nuget 包来: 打开解决方案 枚举其中的项目 发现创建的 DLL。 故障模式似乎超级丰富,我错了……

回答 1 投票 0

Visual Studio 2022 - 嵌套部分类(文件)

我注意到,在我的解决方案中,嵌套部分类仅适用于 Microsoft.NET.Sdk.Web 项目。 对于其余项目(Microsoft.NET.Sdk),它不起作用。 有谁知道吗...

回答 2 投票 0

Microsoft.PackageDependencyResolution.targets(266,5):错误NETSDK1005:资产文件“obj\project.assets.json”没有“net8.0”的目标

我有一个简单的 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 导致上面提到的神秘错误。 希望这可以帮助某人避免因为问题而用头撞墙的两天。

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.