MSBuild, include files based on a group of paths

為{幸葍}努か 提交于 2019-12-13 01:55:38

问题


I'm trying to create a build script which would allow me to specify a list of paths to "module projects" that is included in a specific web site.

Hence, I have this layout:

customer folder
    |_MainProject
    |_ModuleProject1
    |_ModuleProject2

So, basically I want to be able to specify an ItemGroup that would contain ModuleProject1 and 2, and copy relevant files from it into the MainProject.

<ItemGroup>
  <CustomModule Include="ModuleProject1\*.csproj" />
  <CustomModule Include="ModuleProjec2\*.csproj" />
</ItemGroup>

In my main build script I then want to find out the paths to my satellite assemblies, as well as all dlls that reside inside the obj\Release*.dll folder of the project.

I already have item groups for the project file (.csproj), so basically I just want to add some more file references. But I can't figure out how I would do that. This is what I have today:

<Satellites Include="$(ReferencesFolder)\??\*.dll" />
<Satellites Include="$(SiteRoot)\bin\??\*.dll" />
<Satellites Include="%(CustomModule.RelativeDir)obj\$(Configuration)\??\*.dll" />

How would I go about making the last line work based on the facts that I have?

When doing this:

<Message Text="%(CustomModule.RelativeDir)obj\$(Configuration)\??\*.dll" />

It outputs this:

ModuleProject1\obj\Release\??\*.dll
ModuleProject2\obj\Release\??\*.dll

And if anyone has some links to the fundamentals of MSBuild with good examples, I would really appreciate it. I always end up at msdn with some really cryptic examples that doesn't really explain a lot.

EDIT: I revised my plan and almost have it working, however the include doesn't really work as I expect it to. Nothing is included, but there are files mathing the path.

If I manually add this:

<Satellites Include="ModuleProject1\obj\Release\??\*.dll" />

It is actually included in the "Satellites" item group.


回答1:


Found a solution myself, seems like I needed a workaround for it to work explicitly.

Since I wasn't able to include items based on another item list, this was what I finally came up with:

<Target Name="BuildModules">
    <!-- We do this because we need a property with the correct wildcards, otherwise it won't work -->
    <PropertyGroup>
        <CustomModuleSatellites>@(CustomModule->'%(RelativeDir)obj\$(Configuration)\??\*.dll')</CustomModuleSatellites>
    </PropertyGroup>
    <ItemGroup>
        <Satellites Include="$(CustomModuleSatellites)" />
    </ItemGroup>
</Target>

I needed to create a property within a Target (outside of it it didn't fly because it still contained the wild cards), and then use that property ti include the files using wildcards in my item list, otherwise it would be paths with wildcards in it and then the copy command didn't work either.



来源:https://stackoverflow.com/questions/7399589/msbuild-include-files-based-on-a-group-of-paths

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!