MSBuild TargetOutputs不包括Foo.exe.config文件吗? [英] MSBuild TargetOutputs doesn't include Foo.exe.config file?

查看:106
本文介绍了MSBuild TargetOutputs不包括Foo.exe.config文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MSBuild任务,如下所示:

I'm using the MSBuild task as follows:

<MSBuild Projects="Foo.csproj">
    <Output TaskParameter="TargetOutputs" ItemName="FilesToDeploy" />
</MSBuild>

但是,FilesToDeploy项组仅包括由项目文件构建的.EXE文件.它不包含Foo.exe.config文件.

However, the FilesToDeploy item group only includes the .EXE files built by the project file; it doesn't include the Foo.exe.config file.

另一个问题:谁将App.config复制到App.exe.配置?解释了MSBuild如何精确地查找/复制配置文件,但是我不知道如何实际获取名称.

Another question: Who copies App.config to App.exe.config? explains how exactly MSBuild finds/copies the config file, but I can't figure out how to actually get the name.

我发现了一个类似的问题其他地方,但这没有答案.

I found a similar question elsewhere, but that has no answers.

我该如何解决?

推荐答案

让我解释一下这里发生了什么.我将不得不假设您在此处构建的子项目是未经修改的C-Sharp项目.

Let me explain what is happening here. I'm gonna have to assume that the sub-project you are building here is an un-modified C-Sharp project.

默认情况下,.csproj文件的默认目标为生成",因此,当您在此处使用MSBuild任务时,它将在项目中执行默认目标.定义为

By default, .csproj files have a Default Target of "Build", so when you use the MSBuild task here, it will be executing the default target in the Project. This is defined as

   <Target
        Name="Build"
        Condition=" '$(_InvalidConfigurationWarning)' != 'true' "
        DependsOnTargets="$(BuildDependsOn)"
        Outputs="$(TargetPath)"/>

MSBuild任务的文档表明,"TargetOutputs"输出将包含在称为"target"的"Outputs"中声明的项-在这种情况下,它是一个单个项,即被调用项目中属性$(TargetPath)的值.该包含已构建的可执行文件或DLL的名称(请注意,不仅缺少.config,而且缺少所有引用的程序集!)

The documentation for the MSBuild task indicates that the "TargetOutputs" output, will contain the items declared in the "Outputs" of that called target - in this case, it is a single item, namely the value of the property $(TargetPath) in the called project. This only contains the name of the built executable or DLL (note that not only is the .config missing but any referenced assemblies too!)

我要撤回原来的解决方案,因为它无法使用所有生成的输出-这是我在一个实用程序导入文件中设置的目标,但经过调查,看来我实际上并没有使用它

认为,您想要做的是将组成Foo.exe的所有文件(包括.config)放入一个项目组中,以便您可以将它们复制到某个地方.如果考虑所有可以构成csproj输出的内容,这将非常棘手:主要输出(.exe),配置文件,标记为copyLocal的引用程序集,附属程序集(您的.resx DLL),内容项等.

What I think you are trying to do, is get all the files that make up Foo.exe (including .config) into one itemgroup so that you can copy them somewhere. This is pretty tricky, if you consider all the things that can make up the output of a csproj: primary output (.exe), config file, referenced assemblies marked copyLocal, satellite assemblies (your .resx DLLs), Content items etc etc.

如果您知道在构建csproj文件时会将所有项目输出到单个文件夹中,这将非常容易解决.在Visual Studio中进行构建时,这是正确的,因为它将所有编译输出放入bin \ Debug.因此,您会认为FilesToDeploy是$(OutDir)\**\*.*.但是,不是情况是通过TeamBuild构建项目的情况-因为TeamBuild会将OutDir更改为一个全局二进制文件"目录,该目录将每个项目输出到(to防止重复构建等).那就意味着,FilesToDeploy将包含该文件夹的内容,我怀疑这是您想要的.

This is all very easy to take care of if you know that when the csproj file is built, that it will output all the items into a single folder. This is true when building within Visual Studio, as it puts all the compilation outputs into bin\Debug. So you would think that FilesToDeploy is $(OutDir)\**\*.*. But this is not the case when your project is being built by TeamBuild - as TeamBuild will change the OutDir to be a global "Binaries" directory that every project outputs into (to prevent duplicate builds etc). That would mean then that FilesToDeploy would contain the content of that folder, which I doubt is what you want.

毫无疑问,您已经发现了这一点(或至少可以预见到这一点),这就是为什么您有一个目标询问.csproj:您的构建输出是什么,它们在哪里?"的原因.但是,在您可以调用的Microsoft.Common.Targets中没有单个目标声明了构建输出的 entire 集. Azure小组尝试解决该问题(并且可能在他们尝试做的事情中取得了成功),而我试图将其复制到我在此使用的先前解决方案中,但它行不通(或者至少,我没有时间使它工作.)

You no doubt have discovered this (or at least anticipate this), and that is why you have a target that is asking the .csproj "what are your build outputs, and where are they?". However, there is no single Target within Microsoft.Common.Targets that you can call that declares the entire set of build outputs. The Azure group attempted to solve that (and perhaps succeeded within the context of what they are trying to do), and I attempted to copy that in the previous solution that I had here, but it just doesn't work (or at least, I don't have the time to make it work).

这不是全部理想,但是如果您重新访问我击落的假设,并非所有内容都会丢失:如果我们确实知道所有生成的输出都在一个文件夹中同时出现在两个文件夹中时,此问题将更容易解决. VS和TeamBuild.然后,FilesToDeploy将是一个简单的***.* glob.

This is not all ideal, but not all is lost if you revisit an asumption that I shot down: The problem would be easier to solve if we did know that all the build output would appear in a single folder when built both within VS and TeamBuild. Then FilesToDeploy would be a simple ***.* glob.

如果将项目的OutDir修改为TfsBuild.Proj和 force ,则可以实现此目的(例如)$(BinariesRoot)\ FooExe:

You could achieve this if you were to modify your TfsBuild.Proj and force the OutDir of your project to be (say) $(BinariesRoot)\FooExe:

<SolutionToBuild Include=$(SolutionRoot)\Sources\Foo.csproj">
    <Properties>
        OutDir=$(BinariesRoot)\FooExe\
    </Properties>
</SolutionToBuild>

实际上,我有一套完整的自定义捆绑"目标-在.csproj文件中,我可以声明我希望输出的副本进入一组目录,并且这些目标会将所有输出复制到每个目录中.但是,这只是我不得不介绍的内容,因为过去几个月来我逐渐将旧版 nmake.exe 版本转换为本地MSBuild,所以我不想在此发布并搞乱这个答案

I actually have a complete set of customized "bundling" targets - within a .csproj file I can declare that I want copies of the output to go to a set of directories, and the targets will copy all output to each directory. But, that's just something I had to introduce as I have spent the last few months gradually converting a legacy nmake.exe build to a native MSBuild, and I don't want to post that here and mess up this answer

这篇关于MSBuild TargetOutputs不包括Foo.exe.config文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆