简体   繁体   English

使用多个项目发布Web应用程序

[英]Publish Web Application with Multiple Projects

I have an ASP.NET web application that consists of multiple ASP.NET Projects (in addition to multiple class libraries). 我有一个ASP.NET Web应用程序,它包含多个ASP.NET项目(除了多个类库)。 Obviously one of the projects is the root project while the rest are sub projects (the detailed concept of this application structure is explained here ). 显然,其中一个项目是根项目,而其余项目是子项目( 此处解释了此应用程序结构的详细概念)。 Each of the sub/child projects has its own directory and they all sit in a directory I called "Modules" under the root folder. 每个子/子项目都有自己的目录,它们都位于根文件夹下名为“Modules”的目录中。 Since IIS can deal with one project per application, all child projects will be treated as regular directories (upon run). 由于IIS可以处理每个应用程序的一个项目,因此所有子项目都将被视为常规目录(运行时)。 Therefore, I modified the build output path for each of the child projects to " ..\\..\\bin\\ " which is the root bin folder. 因此,我将每个子项目的构建输出路径修改为“ ..\\..\\bin\\ ”,这是根bin文件夹。 That way, I have everything set up correctly. 这样,我就可以正确设置所有内容。 From Visual Studio perspective, I have the luxury of having different projects under one solution. 从Visual Studio的角度来看,我可以在一个解决方案下拥有不同的项目。 And from the IIS perspective I have one project with one bin folder and one Web.Config file. 从IIS的角度来看,我有一个带有一个 bin文件夹和一个 Web.Config文件的项目。 Now it comes to publish. 现在它发布了。 If I publish the root project (by right clicking on the project node --> publish) the published output will be that project only with no "Modules" folder. 如果我发布根项目(通过右键单击项目节点 - >发布),则发布的输出将只是没有“Modules”文件夹的项目。 The resulting bin folder will also miss the sub projects output dlls. 生成的bin文件夹也将错过子项目输出dll。 And that's expected. 这是预期的。 So I thought that the obvious way to fix this is to publish all my web projects (not only the root), having in mind that my sub projects publish path needs to be the "Modules" folder within the root project's publish path. 所以我认为解决这个问题的显而易见的方法是发布我的所有Web项目(不仅是根目录),记住我的子项目发布路径需要是根项目的发布路径中的“Modules”文件夹。 All that worked great except for one essential problem. 除了一个基本问题外,所有这些都很有效。 It turned out that each of the published sub projects has its own bin folder and consequently the root bin folder does not contain the output DLLs of the sub projects. 事实证明,每个已发布的子项目都有自己的bin文件夹,因此根bin文件夹包含子项目的输出DLL。 So I figured, while Visual Studio lets me specify the output path of each project the way I want (as I mentioned I set it to " ..\\..\\bin\\ "), the ClickOnce publish does not respect that and simply creates a bin folder for every sub project. 所以我想,虽然Visual Studio允许我按照我想要的方式指定每个项目的输出路径(正如我提到的那样我将其设置为“ ..\\..\\bin\\ ”),ClickOnce发布不尊重它并且只是创建每个子项目的bin文件夹。 Is there a way to specify the output path (the bin folder) of the ClickOnce publish procedure? 有没有办法指定ClickOnce发布过程的输出路径(bin文件夹)? If not, what would be an alternative solution? 如果没有,那么替代解决方案是什么?

As you said you have multiple projects and one is the root project. 正如你所说,你有多个projects ,一个是根项目。 So every project should have its own bin folder because it is a project not a sub folder of root project . 因此,每个项目都应该有自己的bin文件夹,因为它是一个project而不是root projectsub folder

If sub project would not have a bin folder how it would know from where to load assemblies which are used in that project . 如果sub project没有bin文件夹,它将如何知道从哪里加载该project中使用的assemblies

It is not a bad idea to have bin folder for each sub project . 这是不是一个坏主意,有bin文件夹的每个子project

The answer provided here may address your issue. 这里提供的答案可能会解决您的问题。 By adding the following attributes to your .csproj file (modified from linked answer), you can inform ClickOnce to include additional content in the output directory: 通过将以下属性添加到.csproj文件(从链接的答案中修改),您可以通知ClickOnce在输出目录中包含其他内容:

<ItemGroup>
    <Content Include="bin\**\*.*" />
</ItemGroup>

Another answer given here provides a way to recursively include additional content into your project's output that is outside your project's folder, which may apply here; 这里给出的另一个答案提供了一种方法,可以递归地将其他内容包含在项目文件夹之外的项目输出中,这可能适用于此处; from the root project's perspective, the other project's are outside of it's folder. 从根项目的角度来看,另一个项目是在它的文件夹之外。 However, I'm not sure if ClickOnce will ignore this or not. 但是,我不确定ClickOnce是否会忽略这一点。

<Content Include="..\..\MyContentFiles\**">
    <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM