gpt4 book ai didi

c# - 无法使用 MSBUILD 构建我们的解决方案,它找不到我们的 .targets 文件

转载 作者:行者123 更新时间:2023-12-01 10:03:16 24 4
gpt4 key购买 nike

我已经编写了一些 Windows 批处理文件来为我们产品包含的所有 VS 解决方案调用 msbuild。

除了一个 SLN 外,它们都可以工作,其中 CSPROJ 文件会导致问题。

项目全部在 VS2008 中构建。

项目文件夹布局

\RootFolder
\LinqToXsd
-LinqToXsd.targets
-Xml.Schema.Linq.dll
\BL
-BL.csproj
\Config
-Config.csproj

我们自定义了 CSPROJ 文件以引入 LinqToXsd:

将此行添加到第一个 PropertyGroup:

<LinqToXsdBinDir Condition="'$(LinqToXsdBinDir)' == ''">$(SolutionDir)\..\LinqToXsd</LinqToXsdBinDir>

Microsoft.CSharp.targetsImport 之后的这一行

<Import Project="$(LinqToXsdBinDir)\LinqToXsd.targets" />

命令行:

C:\Windows\Microsoft.NET\Framework64\v3.5\msbuild.exe /m /target:Build /nologo /property:BuildInParallel=true;OutDir=E:\Projects\BuildMaster\trunk\built\ConfigTool\;Configuration=Release /verbosity:minimal "*snip*\ConfigTool\ConfigTool.sln"

问题是,我们在输出中得到了这个:

*snip*\ConfigTool\ConfigTool.csproj(131,11): error MSB4019: The imported project "E:\LinqToXsd\LinqToXsd.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
ConfigTool.csproj : Solution file warning MSB4122: Scanning project dependencies for project "ConfigTool.csproj" failed. The imported project "E:\LinqToXsd\LinqToXsd.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk. *snip*\ConfigTool\ConfigTool.csproj
*snip*\BL\BL.csproj(352,11): error MSB4019: The imported project "E:\LinqToXsd\LinqToXsd.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
..\BL\BL.csproj : Solution file warning MSB4122: Scanning project dependencies for project "..\BL\BL.csproj" failed. The imported project "E:\LinqToXsd\LinqToXsd.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk. *snip*\BL\BL.csproj
C:\Windows\Microsoft.NET\Framework64\v3.5\Microsoft.Common.targets : warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.Xml.Schema.Linq". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

然而,我还有其他项目使用这些线路并完美运行。包括引用相同 CSPROJ 文件的文件(共享 BL)。

我已经尝试删除所有的 bin、obj、缓存、suo 和用户文件/文件夹,没有区别。

有没有 msbuild 专家可以提供帮助?

谢谢,

J1M.

更新1

如果我替换这一行:

<LinqToXsdBinDir Condition="'$(LinqToXsdBinDir)' == ''">$(SolutionDir)..\LinqToXsd</LinqToXsdBinDir>

用这一行:

<LinqToXsdBinDir>$(MSBuildProjectDirectory)\..\LinqToXsd</LinqToXsdBinDir>

在 ConfigTool 和 BL 项目文件中,虽然找不到已编译的 BL dll,但在编译 BL 时,我不再收到有关 LinqToXsd not being found 的错误。

解决方案

首先,SolutionDir 仅由 VS2008 定义,似乎不是 MSBUILD。您可以在命令行中传递它,但我选择执行以下操作:

<LinqToXsdBinDir>$(MSBuildProjectDirectory)\..\LinqToXsd</LinqToXsdBinDir>

MSBuildProjectDirectory 在 VS 和 MSBUILD 中定义。

其次,导致相同症状的不同问题(不知道为什么)

其中一个项目 (BL) 引用了下属 (SL),并且 SL 的 GUID 已更改。这在 VS 中无关紧要,但 MSBUILD 真的不喜欢它。

删除并重新创建引用修复了第二个解决方案。

我只是在我的随机 csproj 黑客攻击期间才发现它,当时 MSBUILD 突然开始报告有关 project {guid} 引用项目 {guid} 的错误,该错误在 SLN 文件中不可用

谢谢,

J1M

最佳答案

MSBuild 未定义 SolutionDir 属性,因此您需要手动指定它:

msbuild.exe /p:SolutionDir=... other options

关于c# - 无法使用 MSBUILD 构建我们的解决方案,它找不到我们的 .targets 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13628319/

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