Publish web project - MSBuild does not copy dependent projects' DLL which are not added reference to web project - visual-studio-2012

My web application basically have three seperated projects:
A web project "MyWeb" which I want to publish to production environment
A Library project "MyBusiness" which define the Business layer's interfaces. This project is referenced by MyWeb project
Another Library project "MyBusinessImplementation" which contain the Business layer's implementation (concrete classes implement the
Business layer's interfaces).
To do Dependency Injection, my MyWeb project just add reference to the MyBusiness interfaces project, not the implementation (or else my web project is closely tied to the implementation, and also I can't prevent my developers from making a "new" object of a concrete class in my web project).
Without adding reference directly to the Business implementation project, when building the project, Visual Studio doesn't know to copy the implementation project's DLL into the web's bin folder, so I added this into MyWeb project file:
<PropertyGroup>
<BuildDependsOn>BuildDependentProjects;$(BuildDependsOn);</BuildDependsOn>
</PropertyGroup>
<ItemGroup>
<ProjectToBuild Include="$(SolutionDir)\MyBusinessImplementation\MyBusinessImplementation.csproj">
<Properties>Configuration=$(Configuration)</Properties>
</ProjectToBuild>
</ItemGroup>
<Target Name="AfterBuild">
<Copy SourceFiles="$(SolutionDir)\MyBusinessImplementation\bin\$(Configuration)\MyBusinessImplementation.dll" DestinationFolder="$(SolutionDir)\MyWebSite\bin"></Copy>
</Target>
<Target Name="BuildDependentProjects">
<MSBuild Projects="#(ProjectToBuild)" />
</Target>
The problem is, when I publish MyWeb project from Visual Studio 2012, or when I run
"MSBuild "MyWeb.jsproj" \T:Package \P:Configuration=Debug"
I see that the MyBusinessImplementation.dll is copied into MyWeb's bin folder of my working code directory but NOT in the published package directory.
I've also tried to change the DestinationFolder of the Copy task to an absolute path like "C:\abc" then I see the .dll file is copied successfully to the abc folder, but still not copied to my Package's web's bin folder.

It looks like you are missing a step of adding the copied item to the WebDeploy manifest and package before its deployed.
Check this post out for a great answer on how to include extra files to the package.
How do you include additional files using VS2010 web deployment packages?

Related

How to add extra files to the package that is generated by msbuild called by an Azure Resource Group Project in Visual Studio

So I have a solution made up of a web project and an Azure Resource Group project much like what is described here: https://blogs.technet.microsoft.com/georgewallace/2015/05/10/deploying-a-website-with-content-through-visual-studio-with-resource-groups/
The issue I am having is that the web project needs to include some EXTRA files in its bin directory in order to function. Now through the normal package process on the web project itself I accomplish this by adding a custom target and hook into CopyAllFilesToSingleFolderforPackageDependsOn, like:
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
</PropertyGroup>
<Target Name="CustomCollectFiles">
<ItemGroup>
<_CustomFiles Include="bin\SlimKIA.WebApi.xml" />
<FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
<DestinationRelativePath>bin\SlimKIA.WebApi.xml</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
And when I right-click on the web project and say "publish" to, say, a file system, my file gets included. All is well and good.
The problem is that this does not happen when I deploy from the deployment project. I have an MsDeploy resource that does its own thing. I need to somehow do my CustomCollectFiles from within this project.
Anyone have any ideas as to how to accomplish this? Without this I am unable to automate the deployment of my solution to Azure.
Thanks!
On a whim I ended up doing this:
<PropertyGroup>
<CopyAllFilesToSingleFolderForMsdeployDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForMsdeployDependsOn);
</CopyAllFilesToSingleFolderForMsdeployDependsOn>
</PropertyGroup>
The key being the CopyAllFilesToSingleFolderForMsdeployDependsOn instead of CopyAllFilesToSingleFolderForPackageDependsOn. Just changing this did the trick, which I guess triggered msdeploy to include the custom target.

Azure sitesroot does not contain all deployed files

I'm deploying a web role to Azure using VS 2013. I added a Contents element to my .csdef file to deploy extra files that are not included in the Azure deployment package like this:
<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="..." xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2014-06.2.4">
<WebRole name="..." vmsize="Small">
<!-- snip -->
<Contents>
<Content destination="bin/">
<SourceDirectory path="C:\...\bin"/>
</Content>
</Contents>
</WebRole>
</ServiceDefinition>
When the package is deployed, I can see the extra files being put in the approot folder on the instance's F: drive. However, these files are never deployed to the sitesroot\0 folder, from which the web role seems to run. Because these extra files are assemblies that are to be loaded dynamically, I would like them to be together with the application's other assemblies.
Is this behavior intentional or am I doing something wrong? There doesn't seem to be much information about this online.
I ended up using the Content element in the end, but with a different destination path, pointing to the sitesroot folder. It's a bit of a hack, but at least it works without diving into MSBuild or manual packaging of the deployment.
<ServiceDefinition name="..." xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2014-06.2.4">
<WebRole name="..." vmsize="Small">
<!-- snip -->
<Contents>
<Content destination="..\sitesroot\0\bin">
<SourceDirectory path="C:\...\bin" />
</Content>
</Contents>
</WebRole>
</ServiceDefinition>
The behaviour is as per the documentation which states that the deployed location is relative to the Role's APPROOT (the behaviour you are seeing).
If you want them deployed into your site's bin folder you need to package them as part of your Visual Studio solution.
You can add a DLL to your root directory of a project (Add -> Existing Item). If you take that DLL and change the Build Action set to Content and the Copy to Output Directory set to Copy Always then I think this will make sure that the DLL ends up being in your BIN folder, or equiv.
An example of what I've done in the past:
Two projects in a Solution named:
DependenciesProject (Class Library)
WebProject (MVC App)
I had a need where some specific DLLs that needed to be bundled into the compiled package were included but the specific DLL that would be used would change based on my compiled targets (x64 vs x86). The solution we chose to go with was to have the DependenciesProject do what I described for you to do above and we modified the .csproj file to change the path to these native DLLs based on the target specified at compile-time (we disabled Any CPU).
So the DependenciesProject had these DLLs in the root directory (with that .csproj having some tweaks for dynamic paths to the DLLs that existed in our Nuget packages folder) and the DLLs in the Solution Explorer had the Build Action set to Content and the Copy to Output Directory set to Copy Always. This means whenever a DependenciesProject.dll file was compiled, it would move the other DLLs into the same output folder as that .DLL file.
Now WebProject project would have a Project Reference to DependenciesProject. This means every time I try to compile WebProject, it will first compile DependenciesProject and then copy its output folder into the WebProject's output folder.
The end result: DependenciesProject.dll as well as MySpecial.dll existed with my web application every time I needed it.
Does this help?

AjaxMin not working on Azure site

I am using Microsoft's AjaxMin to minify javascript on my website, which is hosted by Azure. I am using a BuildTask to automatically minify javascript at run time. This build task is specified in the .csproj file.
The process is working on my local environment, however, it does not work when I deploy to my Azure site. The azure site throws 404: file not found errors, when i try to reference the minified version of .js files.
Is it possible to use build tasks on an Azure site? Is there anything I am missing? I have made sure not to include the .min.js files in source control as this (http://www.asp.net/ajaxlibrary/AjaxMinQuickStart.ashx) tutorial suggests, but I am wondering if there is anything specific to Azure that I need to set up.
Thanks!
I've got this working properly in my projects. I'll tell you how I did it, though this may not be the simplest or most straightforward way.
Before we get started, it's helpful to be able to check if your minified files are included in the Azure deployment package without actually deploying. It's pretty easy to do. The .cspkg file is actually a zip-formatted file, so you can open it with any zip archiver. (I like to use 7Zip for this because the right-click -> Open Archive command doesn't require you to rename the file, but you could use Windows Explorer, WinRAR, etc.) Inside the .cspkg you'll see another large file with a .cssx extension. That's a zip file too. Inside of the .cssx you'll find a sitesroot folder with a subdirectory for each website you're deploying, which will contain all your actual website files. So you can poke around in there and see what files are being deployed to Azure.
First, try editing the project file for your web project (the one that contains all the Javascript/CSS files). You can use Notepad, or in Visual Studio right-click the project, select "Unload Project", then right-click again and select "Edit ". Inside the project file, insert a section like this:
<ItemGroup>
<!-- Copy over all the minified CSS & JS to the output directory-->
<Content Include="**\*.min.css" />
<Content Include="**\*.min.js" />
</ItemGroup>
Then reload the project, repackage it, and see if your files are included in the .cspkg file. If they are, then you're done.
If not, there are a couple other things to check. Your minification might not be running at the right build stage. My minification target looks like this:
<Target Name="PrepWebApp" Condition="$(Configuration)=='Release'" AfterTargets="AfterBuild">
If that's still not working and your Web Role has multiple Sites and/or Virtual Applications in it, it's possible that the packaging steps are not running for all of the sites. So when you go to package your project for deployment to Azure, it may still not be running the minification step (along with the web.config transformations, and some other things). If that's the case, see this blog post for a way to fix it.
Just in case that blog post goes away, I'll copy the most relevant bit here. You would put this in the .ccproj file for your web role (with appropriate bits changed to match your project structure):
<PropertyGroup>
<!-- Inject the publication of "secondary" sites into the Windows Azure build/project packaging process. -->
<CoreBuildDependsOn>
CleanSecondarySites;
PublishSecondarySites;
$(CoreBuildDependsOn)
</CoreBuildDependsOn>
<!-- This is the directory within the web application project directory to which the project will be "published" for later packaging by the Azure project. -->
<SecondarySitePublishDir>azure.publish\</SecondarySitePublishDir>
</PropertyGroup>
<!-- These SecondarySite items represent the collection of sites (other than the web application associated with the role) that need special packaging. -->
<ItemGroup>
<SecondarySite Include="..\WebApplication1\WebApplication1.csproj" />
<SecondarySite Include="..\WebApplication2\WebApplication2.csproj" />
</ItemGroup>
<Target Name="CleanSecondarySites">
<RemoveDir Directories="%(SecondarySite.RootDir)%(Directory)$(SecondarySitePublishDir)" />
</Target>
<Target Name="PublishSecondarySites" Condition="'$(PackageForComputeEmulator)' == 'true'
Or '$(IsExecutingPublishTarget)' == 'true' ">
<!--
Execute the Build (and more importantly the _WPPCopyWebApplication) target to "publish" each secondary web application project.
Note the setting of the WebProjectOutputDir property; this is where the project will be published to be later picked up by CSPack.
-->
<MSBuild Projects="%(SecondarySite.Identity)" Targets="Build;_WPPCopyWebApplication" Properties="Configuration=$(Configuration);Platform=$(Platform);WebProjectOutputDir=$(SecondarySitePublishDir)" />
The build task will run in Visual Studio when you build the project. You need to make sure that the minified files are also being deployed to Azure.
I'm guessing that perhaps because the item is being generated at build-time that it's not part of the project itself, and is this ignored by the deployment step.
Please check that the deployment system being used will include all the script files and not just the ones that are in the project itself.

Can the default location of an Orchard CMS module be changed?

I'm setting up an Orchard CMS project with the intention of creating a module to house my MVC 3 application. This application has already been started and has 5 projects already. One web project, some test projects and a workflow project.
Requiring that the web project (and therefore the other 4 projects for simplicity) lives within /Orchard.Web/Modules/ is a minor inconvenience - is it possible to change where Orchard looks (or add a new location) when dynamically loading the modules?
It's not a massive deal, but a nice to have for this project.
In an ideal world i'd be able to have:
/OrchardStuff/Orchard.Web
/OrchardStuff/etc
/MyStuff/MyProj.Web
/MyStuff/MyProj.Tests
I know i can arrange my sln in a nice usable way, would be nice if i could replicate this in the file system.
Cheers.
Wouldn't be easier to add an afterBuild task in your web project to copy the application to the Orchard's modules directory?
Something like that in the csproj file would do the trick (sort of, I am not entirely sure of my syntax. :'( )
<Target Name="AfterBuild">
<ItemGroup>
<AppFiles Include="**\*.*"/>
</ItemGroup>
<Copy SourceFiles="#(AppFiles)"
DestinationFiles="#(AppFiles->'..\OrchardStuff\Orchard.Web\Modules\MyModule\%(RecursiveDir)%(Filename)%(Extension)')" />
</Target>
The MSDN documentation is here: http://msdn.microsoft.com/en-us/library/3e54c37h.aspx
The solution I used is adding the following line to post-build operation:
if not exist "$(SolutionDir)..\Orchard\src\Orchard.Web\Modules\$(ProjectName)" mklink /D "$(SolutionDir)..\Orchard\src\Orchard.Web\Modules\$(ProjectName)" ""$(ProjectDir)"
This command creates a symlink of your dev folder inside Orchard's Modules folder (only if such symlink doesn't already exist).
It has the following advantages over #Eilistraee's answer:
If you change Javascript/CSS file in your dev machine, you don't need to build the project to get the changes into Orchard.
You don't get duplicate files on your drive
Post-build is a more explicit option and the macro variables make it easy to copy to any new module.
No that's not possible without some major efforts. Not worth it.

How to deploy an assembly using the Team Definition in Sharepoint?

Now i am using the sharepoint extensions 1.2 for Visual Studio 2005 to deploy my website. I want to add an assembly to the bin, but i don't know how to add it to the Team Definition.
Could someone give some code, plz?
OK I found a solution.
First you have to add the assembly you want to deploy into the VS project. For example you can create a "libs" folder to store all external assemblies you'll need in your team site.
Then you have to edit the manifest.xml file of your Team Site Definition. You can find this file within the "pkg" folder within your project. Be aware that the pkg folder will only be available if you've at least deployed the solution one time.
OK, now you have to add a new <Assembly> child element to the <Assemblies> element within the manifest.xml file of your Team Definition solution. With the "DeploymentTarget" Attribute you can define whether the assembly should be deployed to the GAC or to the web application's bin folder.
The following example shows how the <Assemblies> element looks like if you want to add the "TeamSiteDefinition1.dll" to the GAC and to add the "TestSolution.dll" to the bin folder. If you need a safe control entry for your assembly you can add this one too.
<Assemblies>
<Assembly Location="TeamSiteDefinition1.dll" DeploymentTarget="GlobalAssemblyCache" />
<Assembly Location="TestSolution.dll" DeploymentTarget="WebApplication">
<SafeControls>
<SafeControl ..... />
</SafeControls>
</Assembly>
</Assemblies>
If there's any SharePoint-relevant code (web part, event receiver etc) in your project, the assembly will be packaged up in the resulting WSP and your solution manifest will already have an instruction to put it into the GAC. Any particular reason you need it in the bin rather than the GAC? It can be done -- read up the documentation on the Solution Manifest XML format -- but requires manipulating the solution manifest from WSP View manually, and might require re-creating the WSP with WspBuilder.

Resources