Assembly in GAC is not copied to output in project that references a project that references the GAC assembly with CopyLocal=true

前端 未结 3 1805
囚心锁ツ
囚心锁ツ 2021-01-04 02:38

I have a \"Project A\" that references System.Web.Mvc with CopyLocal=TRue. System.Web.Mvc is in the GAC both on my local maching and on the buildserver.

I also have

相关标签:
3条回答
  • 2021-01-04 03:14

    A pragmatic (read hack) solution is that I referenced System.Web.Mvc.dll in "Project B". This is definitively not the right solution, so please bring me a better solution :-)

    0 讨论(0)
  • 2021-01-04 03:15

    One suggestion I've seen floating around for this one is to change all of your projects to have the same output path. This is of limited value though, since if you have a dependency chain like: Prj B > Prj A > Lib C Then it's probably because Prj A is shared across multiple applications, for which you will want to each have their own output path.

    I resolved the issue by instead using MSBuild to compile, and setting the OutDir property on each build.

    e.g. MSBuild projectB.csproj /p:OutDir=C:\AppBOutput\

    This will put the output for project B, its dependent projects (prj A), and prj As copy local dependencies all into the C:\AppBOutput\ directory.

    Why it Works

    When building the project in Visual Studio, both prj A and prj B have their own output directory, e.g. prjA\bin\debug and prjB\bin\debug. The GAC-stored assembly set to copylocal will be included in the output directory of the project that directly references it (prjA). But it will not be copied to the output directory of the project referencing that project (prjB). That's just how the project reference copying works. Dig into the MSBuild targets and I'm sure the underlying reason could be found (sorry, not doing it myself).

    What the /p:OutDir=C:\AppBOutput\ MSBuild parameter does, is set the output directory of all projects to be the same. By doing this, you side-step the MSBuild behaviour of how it copies project-to-project reference outputs. Instead of relying on MSBuild to copy some of the content in prjA\bin\debug to prjB\bin\debug, you just force all projects to output to the same directory.

    0 讨论(0)
  • 2021-01-04 03:36

    Did you check the .csproj file to verify that the reference does indeed contain the <Private>True</Private> tag? Copy local is unfortunately has 3 states in the xml - True, False and ... missing.

    0 讨论(0)
提交回复
热议问题