VS2017: Solution builds but publish fails - msbuild

I have a solution with 3 Websites and 1 Web API project. When I build the solution there is no issue but when I publish the Web API project to file folder, I get a lot of errors and the publish fails. One of the error is:
Error CS0006 Metadata file
'D:\Projects\MyAppName\Code\MyAppName\BusinessObjects\bin\Release\BusinessObjects.dll'
could not be found.
Other issues are similar to:
Error CS0246 The type or namespace name 'Amazon' could not be found
(are you missing a using directive or an assembly reference?)
I have checked in the project. The referenced DLL(Amazon) is available and this issue doesn't occur when I build the solution.
What could be the issue? I have also checked if there is any missing file(checking for yellow exclamation icon in front of file name) but I couldn't find one.

VS2017: Solution builds but publish fails
(According to the error messages, they are all common errors. we could not give the most direct correct answer for this issue, we can only give you some troubleshootings. In order to avoid losing contact in the round-trip comments, I post those troubleshootings as answer instead of comments.).
You can try:
Clean solution then rebuild it.
Go to Solution Explorer. Right click on Solution. Go to Properties. Go to Configuration Manager. Check if the checkboxes under Build are checked or not. If any or all of them are unchecked, then check them and try build the solution again.
Remove the project reference and then adding it back in again, and check if all those missing dll file exists in the bin folder.
Delete bin/obj folder, build again and try to restart Visual Studio.

Related

Visual Studio 2013 C# Web Project builds but IDE reports The type or namespace name xxx could not be found error

When opening an MVC4 C# web project in Visual Studio 2013, the IDE reports the error "The type or namespace name '_' could not be found (are you missing a using directive or an assembly reference)", but the project builds and runs without any errors. Furthermore, intellisense does not include the project namespace.
The "missing" reference is to files within the same project.
for example; the web project namespace is "webproject.com", and references in a controller files to "webproject.com.models" is underlined in red with the error above.
I have checked the following:
All Solution projects are configured to use the same Target Framework(.Net 4)
web.config in the Views folder contains the namespace in the system.web.webPages.razor section
cleaned and rebuilt solution
deleted all bin and obj content
deleted .suo and .csproj.user files that were created by VS2010
The only way that I can get rid of these errors being reported in VS2013 is to unload then reload the project.
When opened in Visual Studio 2010 I do not get these problems.
I have the same issue.
ALthough the project compiles correctly, the code editor shows an error The type or namespace name '_' could not be found (are you missing a using directive or an assembly reference).
THere is one workaround. Just delete the *.SUO files and re-open the solution. THen for this only Session it works. Unfortunately after closing and reopening the solution the issue is back again. VS 2012 works fine.
Seems to be a bug in VS 2013....
My solution, when I encountered the problem with VS 2013 Express edition was to simply unload the offending project and reload. Opening the SUO or Project file and making changes had not affect.
Try to unload the project in VS2013, then right click the node and select edit "projectname.csproj". Check the individual references they might point to somewhere strange.
EDIT: the csproj file is an xml file and the references are located under Project -> ItemGroup -> Reference
I had the same issue.
It's a VS 2012 solution with different projects.
Search for all *.suo files and deleted them.
Rebuild and reopen Visual Studio.
There's a known issue with Web Application projects when bound to a TFS server that sounds like this issue. This occurs when the following TFS setting option is checked:
Options -> Source Control -> Environment -> Get everything when a solution or project is opened.
Disabling this option resolves the problem.
thanks,
Miguel Lacouture
[MSFT]
Same issue, on project reference.
I opened the referenced project file (*.csproj) with a text editor and did some cleanup:
1) reset these properties' values:
<PublishUrl>publish\</PublishUrl>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<IsWebBootstrapper>false</IsWebBootstrapper>
<TargetFrameworkProfile />
2) removed dirty platform/configurations:
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'x86|AnyCPU'">
...
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'x86|x86'">
...
Now I can compile without any issue.
Glad to share it with you! :))
Same issue. Opening the project's properties and making a change to the name (or any value) and then rebuilding seems to have resolved it.
I have just had this problem and none of the solutions here helped. I fixed mine by doing a repair of Visual Studio (An option when you select to uninstall the program). Hope this helps someone
I had same issue when I added a new class file ( e.g. MyClass.cs) and called it in some other C# code places. For some reason VS did not add that new class file to my working project folder (not seen in VS, but seen in Windows File Explorer). And, hence, the compile path for new class file is not included in the compile section of my project file (e.g. MyProject.csproj). So to solve this problem, First, right click on your working project > Add > Existing Item ... > Select your new class > OK.
Then, check the project file (*.csproj) and make sure a new element is inserted in the compile section such as:
Finally, rebuild your project and the problem should be solved.
Another reason for this issue is the project, I had long ago with VS, is my other project was set up with Client Profile as its target framework. So, to solve the issue: Right click your project in VS > Properties > Application tab > make sure Target Framework option is not Client Profile. You should change all projects in your solution to the same framework version AND all of them must not have Client Profile option.
Microsoft just released a new security update to be automatically applied to machines configured to use Microsoft Update.
Unfortunately, some ASP.NET MVC 3 and 4 VS projects can no longer build after the update is applied. These projects will fail with the following error:
"Could not locate the assembly "System.Web.Mvc,Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35,processorArchitecture=MSIL"
My project also had the error "The type or namespace name 'System.Web.Mvc' could not be found (are you missing a using directive or an assembly reference)". Installing the latest version of Microsoft.AspNet.Mvc solved my problem. See the following article from Microsoft for more info:
http://blogs.msdn.com/b/webdev/archive/2014/10/16/microsoft-asp-net-mvc-security-update-broke-my-build.aspx
Unloading and then reloading the project worked for me.

SD.LLBLGen.Pro.DQE dll missing. From where can i get it?

I have a project which uses "SD.LLBLGen.Pro.DQE.OracleMS.NET20" reference.
I did some blunder and it's missing now.
I am getting Build Error:-
The type or namespace name 'Oracle' does not exist in the namespace
'SD.LLBLGen.Pro.DQE' (are you missing an assembly reference?).
Can any body help me in this, tried googling but no fruitful result??
Apologies, if the question is put in wrong section .
If you have LLBLGen installed locally, you should find the file in a location something like this:
C:\Program Files (x86)\Solutions Design\LLBLGen Pro v3.1\Frameworks\LLBLGen Pro\RuntimeLibraries\Net2.0\SD.LLBLGen.Pro.DQE.OracleMS.NET20.dll
You can correct the path of the broken reference to point to this file. Or, better yet, copy this file into your source control location for the project so other team members can compile the project without having the full LLBLGen installation.
If you don't have this file locally but have a customer ID you can log in here to download the installer:
https://www.llblgen.com/pages/customerlogin.aspx
I suspect the trial version also comes with this file, but have not tried that approach.

msbuild failing with "cannot find a a part of the path"

I'm running msbuild on my .sln file and I'm suddenly getting
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(2291,5):
error SB3554: Cannot write to the output file "C:\Work\product\src\component\
obj\Debug\product.resources". Could not find a part of the path 'C:\Work\
product\src\component\obj\Debug\component.Resources.resources'. [C:\Work\
product\src\component\component.vbproj]
No amount of deleting binaries and retrying helps
Had a similar intermittent problem, added these options to the copy command
Retries="10" RetryDelayMilliseconds="5000"
and it seemed to do the trick
The error states product.resources is failing because component.Resources.resources cannot be found.
Ensure your project build order is correct since resources files are built at compile time and it cannot find the needed resources file to continue.
Another solution you might try is to delete and re-add any .resx files in your projects.
Also, I would create one shared project with resources for the solution to make it easier to mange your resources. Here is an example although a little dated.
How to use shared resource file between projects in one solution?
MSDOCS-Packaging and Deploying Resources in .NET Apps

allowDefinition='MachineToApplication' msbuild error

We have a ASP.NET MVC with 4-5 different build configurations. Whenever we change the build configuration, we need to delete the obj folder for the web project, since we get the 'allowDefinition='MachineToApplication' error. A pain, but we managed by deleting the folder in pre/post build events.
Now I need to configure our CI to build deployment packages. This means that I cannot delete the obj folder. Every time I compile e.g. with the following msbuild parameters
/p:CreatePackageOnPublish=true /p:DeployOnBuild=true
I recieve the error:
web.config(123): error ASPCONFIG: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.
As far as I understand, the problem is that there's multiple .config files in the project - In our case, there's not. I could really use some help to find an explanation and find a permanent (no- hack) fix.
Edit:
This question is marked as a duplicate, but the corresponding answers and cause(s) in the 2 threads, are clearly different from each other. Not sure what is intended with this tag - I've read that particular post before posting this question, as it didn't answer my question. There's multiple causes for this error message. It is 'similar', but definitely not a duplicate!
There is a similar question here on SO with some good solutions for this issue.
The problem is that building a deployment package creates a copy of the web.config in a subfolder of /obj. That will normally be be cleared out if you do a rebuild or a clean. However, if you build a deployment package in one configuration (e.g. Debug) and then switch to another confguration (e.g. Release) the obj/Debug folder is not cleared out and the web.config file there causes problems.
The quick solution is to clean all configurations and then do a (re)build. Alternatively you could delete the /obj folder in your project.
To permanently resolve the issue you can either move the intermediate output (/obj) out of your project folder or modify the project to force a clean of all configurations on rebuild.
I too was deleting the obj folder until I had a conflict with a build script which required it. Catch-22, I used the accepted answer on the following SO link to move the location of the Obj folder to C:\Temp\BUILD. You have to do it per csproj file, but it is a great solution.
Here is the link: VisualStudio: How to save the obj folder somewhere else
Note that I am using a variable for the project name.
R:\Temp\Build\Debug\$(MSBuildProjectName)
I have the above line in both debug and release sections for all my projects, including class projects. My build path is a ram drive for speed. See this SO for more info: How to access macro variables within csproj file?
I just answered a similar question here. To recap, I ran into this problem in one of our MVC projects, and it was due to having the MvcBuildViews property in the project file set to true. Setting the property to false fixed the problem.
<MvcBuildViews>false</MvcBuildViews>
I also found this answer which outlines an alternative that does not require turning off view building.
I don't know that there is an "official" fix as it just seemed to start on multiple projects of mine for no reason that I can find in Visual Studio Premium 2012 (never happened in previous versions of VS).
As a work around to automate the deletion of the obj directory as others have said, similar to an answer by user Casual in this post VisualStudio: How to save the obj folder somewhere else, where unfortunately just moving the location of the obj folder didn't always seem to work.
Instead I added a few commands under Build Events in the Pre-build event command line:
rd "$(ProjectDir)obj" /S /Q
md "$(ProjectDir)obj"
md "$(ProjectDir)obj\Debug"
md "$(ProjectDir)obj\Release"
You can change/add/remove subfolders to match your custom build configurations using the line where buildConfigName matches the name of the build configuration you are using:
md "$(ProjectDir)obj\buildConfigName"
Hope this helps!
That error indicates that you are trying to something specific to an application at an IIS tree level that isn't defined as an application. For example if you try to do app-level functions in a web.config in a virtual directory, you will get that error. You need to find the path you are deploying to and make sure that it is defined in IIS as an application vs a folder or vdir.
Cleaning the solution (Right click Solution in VS, clean), worked for me.
I had the same error but with a deployed page.. Then realized my webserver's clock was set back to 2010 for some reason. set it to the correct date fix my problem
Clean your project
Remove the /obj folder (probably using publish and deploy? - there is a bug in it)
Althoug the problem is explained and solved in one way in the accepted answer, I wanted to show a solution which can be better for other cases. This solution has been included in some version of VS, but I can only say that I had the problem in VS 2013 Update 5. (See the "Beware" below, it could be fixed in this version, but not working only in my particular case).
I borrowed the soltuion from Error: allowDefinition='MachineToApplication' beyond application level on Visual Studio Connect.
The solution consist in including these lines to the web application project (.csproj file) which handle the deletion of the offedning intermediate files (which wans't a solution for the accepted answer, as he needed those intermediate files):
<!--Deal with http://connect.microsoft.com/VisualStudio/feedback/details/779737/error-allowdefinition-machinetoapplication-beyond-application-level,
we will need to clean up our temp folder before MVC project starts the pre-compile-->
<PropertyGroup>
<_EnableCleanOnBuildForMvcViews Condition=" '$(_EnableCleanOnBuildForMvcViews)'=='' ">true</_EnableCleanOnBuildForMvcViews>
</PropertyGroup>
<Target Name="CleanupForBuildMvcViews" Condition=" '$(_EnableCleanOnBuildForMvcViews)'=='true' and '$(MVCBuildViews)'=='true' " BeforeTargets="MvcBuildViews">
<ItemGroup>
<_PublishTempFolderNamesToCleanup Include="Database;TransformWebConfig;CSAutoParameterize;InsertAdditionalCS;ProfileTransformWebConfig;Package;AspnetCompileMerge" />
</ItemGroup>
<!--Force msbuild to expand all the wildcard characters so to get real file paths-->
<CreateItem Include="#(_PublishTempFolderNamesToCleanup->'$(BaseIntermediateOutputPath)**\%(identity)\**\*')">
<Output TaskParameter="Include" ItemName="_EvaluatedPublishTempFolderNamesToCleanup" />
</CreateItem>
<Delete Files="#(_EvaluatedPublishTempFolderNamesToCleanup)" />
</Target>
Beware: for some reason, probably because I included it myself in the project, my build target for building the views was named "BuildViews", instead of "MvcBuildViews", so I had to modify the BeforeTargets attribute accordingly.
This is not necessarily the exact same issue, and to be honest, probably down to pure lack of knowledge on my part, however I had this same error when:
I set up a standard asp.net new project actually just used for HTML5 stuff so nothing other than the usual project structure
I then (not thinking perhaps!) added a new WCF REST project (which actually was just another base asp.net project using very good examples from http://www.codeproject.com/Articles/128478/Consuming-WCF-REST-Services-Using-jQuery-AJAX-Call?fid=1597004&df=90&mpp=25&noise=3&prof=False&sort=Position&view=Quick&fr=26#xx0xx and http://geekswithblogs.net/michelotti/archive/2010/08/21/restful-wcf-services-with-no-svc-file-and-no-config.aspx
The problem was I added the WCF REST project (#2) as a SUB-DIRECTORY of the main project (#1) and then tried to build! even if I cleaned the project of course.. I also made both projects use IISexpress because I thought there was an issue using the same port or something.
Of course the build process saw the web.config from #1 and then a sub-dir with another web.config #2..
I realise this probably should be a very basic understood gotcha and it has caught me out a while ago, however sometimes it's the simplest of mistakes that are a real pain!
Might help others... who perhaps haven't had their morning coffee..
tip 1: clean & then rebuild.
tip 2: just close VS and open again.
tip 3: the downloaded project may be inside another sub folder... open the folder which has you .net files.
c:/demo1/demo/ (all files)
You should have to open demo from vs... not demo1.
I have a somewhat a similar problem, i had the main config as Copy Always so it copied the config to the bin directory. When i republished the main project, i got the MachineToApplication error. So my solution was to just change the config to Do Not Copy and remove the extra configuration in the bin folder.

MSBuild Click-Once issues with manifest

I am getting the following error when I publish my ClickOnce application with MSBuild. I have a pre-publish task which copys the correct app.config file into the project before the publish and this is the only thing that I think could be causing this error. How can I correct this?
Following failure messages were
detected: File,
MyApplication.exe.config, has a
different computed hash than specified
in manifest.
You're copying the file after the hash is generated.
You need to copy the file during BUILD and before PUBLISH. The ClickOnce mechanism thinks there is tampering going on.
Brett's answer is correct, the GenerateManifests target gets run in the middle of the CoreBuild target (in Microsoft.Common.targets) so the best place to update the build file is in BeforeBuild.
I'm guessing the reason you are switching the app.config is to replace the config with one that has the right values for the environment you are publishing too? If that is the case have a read of my posting on publishing to multiple environments...will help to answer questions like 'how do I override the BeforeBuild target?'.
Sign the click-once manifists and (re)create a Test Certificate for you application under the signing tab in the project properties... This solved the problem for me. Good Luck