gpt4 book ai didi

c# - .csproj 文件中未通知时,Visual Studio 如何确定输出路径?

转载 作者:太空宇宙 更新时间:2023-11-03 18:06:45 25 4
gpt4 key购买 nike

我正在尝试从另一个解决方案引用 C# DLL 项目,但构建在一个非常奇怪的输出文件夹中生成 DLL。

目录内容是这样的:

c:\a\b\c\src\Solution.sln
c:\a\x\y\z\MyDLL\MyDLL.csproj

MyDLL.csproj 没有 <OutputPath>标签。不过,它确实有一个我不常看到的 标签。

如“属性” View 中所示,计算出的输出路径恰好是:

..\..\..\..\b\c\src-z\MyDLL\objd\i386

这对应于这个路径:

c:\a\b\c\src-z\src\MyDLL\objd\i386

这很奇怪,因为我不知道 src-z 配置中的任何内容。 Visual Studio 是否计算带有连字符的路径?

我想解决这个问题,可能会更改 ,但我不想破坏其他解决方案。

计算似乎发生在构建过程的早期,因为构建器记录的第一件事是:

1>Project 'MyDLL (x\y\z\MyDLL\MyDLL.csproj)' is not up to date.
Input file 'x\y\z\MyDLL\MyDLL.csproj' is modified after output
file 'c:\a\b\c\src-z\src\MyDLL\objd\i386\MyDLL.pdb'.

那么,当找不到项目 标记时,Visual Studio 使用什么算法来计算输出路径?

最佳答案

填充 OutputPath 的代码可以在 C:\Program Files (x86)\MSBuild\12.0\Bin\Microsoft.Common.CurrentVersion.targets 中找到(默认情况下;如果 MSBuild 安装目录不同,它可能会发生变化)。

关于它的评论是:

OutDir:

Indicates the final output location for the project or solution. When building a solution, OutDir can be used to gather multiple project outputs in one location. In addition, OutDir is included in AssemblySearchPaths used for resolving references.

OutputPath:

This property is usually specified in the project file and is used to initialize OutDir. OutDir and OutputPath are distinguished for legacy reasons, and OutDir should be used if at all possible.

因此,虽然通常引用的是 OutputPath,但实际上重要的是 OutDir。如果没有设置平台或配置,则 OutputPath 设置为 bin\Debug\ .

如果我们查看该文件,我们可以看到设置 OutDir 的逻辑很简单。如果OutDir未设置则设置为 OutputPath .如果 GenerateProjectSpecificOutputPath,则将以项目命名的文件夹附加到路径有一些额外的逻辑。已设置。

查看Microsoft.CSharp.targets , Microsoft.CSharp.CurrentVersion.targets , Microsoft.Common.TargetsMicrosoft.Common.CurrentVersion.targets , 既不OutDir也不OutputPath似乎设置在其他任何地方。因此,假设一个“开箱即用”的 C# 项目,它基本上等于 OutDir , OutputPath , 或 bin\Debug .

最后一点相关信息是工作目录。 OutDir可以是相对路径,在这种情况下它将位于工作目录中的某个位置。

至于BaseIntermediateOutputPath ,信息在同一个文件中:

BaseIntermediateOutputPath:

This is the top level folder where all configuration specific intermediate output folders will be created. Default value is obj\

IntermediateOutputPath:

This is the full intermediate Output Path, and is derived from BaseIntermediateOutputPath, if none specified (eg. obj\debug). If this property is overridden, then setting BaseIntermediateOutputPath has no effect.

看逻辑,默认是obj\如果未设置(请注意,相对路径,以便工作目录再次发挥作用)。

关于c# - .csproj 文件中未通知时,Visual Studio 如何确定输出路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27073463/

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