Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用更新的框架引用或复制其他C#项目的输出?_C#_Msbuild - Fatal编程技术网

如何使用更新的框架引用或复制其他C#项目的输出?

如何使用更新的框架引用或复制其他C#项目的输出?,c#,msbuild,C#,Msbuild,情景: Loader.csproj,即.NET4.8;并输出具有某些.dll依赖项的.exe LoaderRapper.csproj,它是.NET 4.6,需要使用一些参数调用Loader的.exe Main.csproj,即.NET 4.6,通常引用LoaderRapper 我无法从LoaderRapper.csproj创建对Loader.csproj的常规项目引用,因为Loader.csproj是一个较新的.NET framework 我无法创建程序集引用,因为它只复制.exe文件,而不复制

情景:

Loader.csproj,即.NET4.8;并输出具有某些.dll依赖项的.exe
LoaderRapper.csproj,它是.NET 4.6,需要使用一些参数调用Loader的.exe

Main.csproj,即.NET 4.6,通常引用LoaderRapper

我无法从LoaderRapper.csproj创建对Loader.csproj的常规项目引用,因为Loader.csproj是一个较新的.NET framework

我无法创建程序集引用,因为它只复制.exe文件,而不复制Loader.csproj的.exe所依赖的任何.dll文件

在3d party应用程序Revit(即.NET 4.6)中加载应用程序时,我无法更改框架版本

我不能硬编码Loader.csproj的输出,因为在我的构建管道中有几个不同的输出目录。(例如,用于单元测试)

在Visual Studio中,我可以更改LoaderRapper.csproj上的“生成依赖项”->“项目依赖项”,以确保生成Loader.csproj,但这似乎不会复制/引用Loader.csproj的输出


因此,我正在寻找另一种方法来确保Loader.csproj的所有输出都包含在loaderRapper.csproj中,并通过projectreferences最终包含在Main.csproj中。

不久前,我解决了类似的任务-从一个项目收集内容文件,并将其包含到另一个项目的输出中。 这与你的任务并不完全相同,但你可以尝试采用我的方法

所以,我有一个名为MainApp的项目和一个名为Lib的项目。Lib项目的txt文件ContentFile.txt的buildaction=Content。我需要将ContentFile.txt包含到MainApp的输出中

我在Lib文件夹中创建了包含以下内容的
CustomBuildActions.targets
文件

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <!--
    Define project to get content files from.
    Definition relies on the fact that this target file stored
    in the same folder with Lib.csproj
    -->
    <ItemGroup>
        <LibProject Include="$(MSBuildThisFileDirectory)/Lib.csproj"/>
    </ItemGroup>

    <!--
    Run msbuild for Lib to collect the list of Content files and store it to the LibContentFiles list.
    Then perform string repace to convert paths to Content files to paths inside app bundle. And store results in the LibContentFileTargetPath.
    -->
    <Target Name="GetBundleFiles" Outputs="@(LibContentFiles)">
        <MSBuild Projects="@(LibProject)" Targets="ContentFilesProjectOutputGroup">
            <Output ItemName="LibContentFiles" TaskParameter="TargetOutputs"/>
        </MSBuild>

        <ItemGroup>
            <LibContentFileTargetPath Include="@(LibContentFiles->Replace($(MSBuildThisFileDirectory), $(AppBundleDir)/Contents/Resources/))"/>
        </ItemGroup> 
    </Target>

    <!-- These targets will fire after mmp creates your bundle but before code signing -->
    <PropertyGroup>
        <CreateAppBundleDependsOn>$(CreateAppBundleDependsOn);GetBundleFiles;CopyOurFiles;</CreateAppBundleDependsOn>
    </PropertyGroup>

    <!-- Since this has inputs/outputs, it will fire only when the inputs are changed or the output does not exist -->
    <Target Name="CopyOurFiles" Inputs="@(LibContentFiles)" Outputs="@(LibContentFileTargetPath)">
        <Message Text="This is us copying a file into resources!" />
        <!-- This could have easily been done w/ a built in build action, but you can extend it arbitrary. -->
        <Copy SourceFiles="@(LibContentFiles)" DestinationFiles="@(LibContentFileTargetPath)" />
</Target>
</Project>

$(CreateAppBundledPendson);GetBundleFiles;复印文件;
然后在MainApp项目中导入此目标

  <Import Project="../Lib/CustomBuildActions.targets" />

此自定义目标将从Lib项目中收集内容文件,转换路径以在MainApp输出中保留文件夹结构(例如,如果我们在Lib项目中有Lib/ContentFolder/Subfolder/contentFile.txt之类的内容,那么在包中if将放在Resources/ContentFolder/Subfolder/contentFile.txt中)然后复制捆绑包中的文件

因此,您需要采取什么措施:

  • 使用加载器项目的输出项,而不是内容文件。因此,您需要的不是
    ContentFilesProjectOutputGroup
    ,而是其他目标。请参阅msbuild文档以查找最适合您的内容
  • 更改目标依赖项-您的自定义目标应该成为LoaderRapper项目构建步骤的依赖项(在我的示例中,我使用
    CreateAppBundleDependsOn
    依赖项,但这是Xamarin唯一的事情,您需要找到更好的步骤来添加依赖项)

  • 我的案例的完整描述可以在这里找到

    您是否尝试过预构建事件?您可以将git中的子模块功能与预构建事件结合使用