How to set web.config to "debug=false" via MSBuild Extension Pack? - msbuild

I have an WCF Service Application and the web.config is set to debug mode (debug = true):
<compilation debug="true">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
I would like to set that to "debug=false" via MSBuild Extension Pack (version 3.5.8.0), so that the released version is always automatically in non-debug mode.
Obviously I need to use the XmlFile class, but it doesn't do anything.
My build file looks like this:
<Target Name="Test">
<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="UpdateAttribute" File="$(MSBuildProjectDirectory)\$(BuildDir)\ServiceClient\web.config" XPath="/configuration/system.web/compilation[#name='debug']" InnerText="false"/>
</Target>
When I run the build script, I only see this:
Test:
XmlFile: C:\MyProject\Build\ServiceClient\web.config
Update Attribute: /configuration/system.web/compilation[#name='debug']. Value:
No errors, no warnings...nothing.
I can see that MSBuild found the web.config and did something with it, because "Date Modified" in the Explorer is set to right now, which wasn't the case before I ran the script. But there is no visible change in the file. I used a diff tool to compare the file versions before and after MSBuild, and they are identical.
I also tried to set Key and Value instead of InnerText, but that doesn't help either.
Any idea what I'm doing wrong?

Try this:
<Target Name="Test">
<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="UpdateAttribute" File="web.config" XPath="/configuration/system.web/compilation" Key="debug" Value="false" />
</Target>
I am using extension pack version 3.5.8.0

Related

VS Community - VB - Unable to read to or write from app.config via Settings dialog

Recently I posted a couple of errors I was having, relating to app.config in a VB project. Andrew Morton kindly pointed me to an existing answer which resolved the first part of the issue, but I've since found that I still can't add/update variables in app.config via the Settings dialog in the project properties, nor can the Settings dialog read the app.config file.
The error message is:
an error occurred while reading the app.config file. the file might be corrupted
If I manually change the variable in app.config the program I'm coding still finds the old value as it's taking it from Settings.Designer.vb, and that's not getting updated when I change the variable in Settings as the platform isn't reading the app.config.
I've (again) run the app.config through an XML checker, all fine. I read one solution for this issue, which suggested the cause can be duplicate elements in the 'sectionGroup' area of app.config, but mine doesn't appear to have duplicate elements (app.config posted).
Steps I have tried are:
Removed and re-added the project from the solution.
Updated VS.
Repaired VS.
Deleted the app.config file and the variables from the Project Properties - System dialog, then added a new app.config and recreated the variables in the System dialog.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="system.diagnostics" type="System.Diagnostics.DiagnosticsConfigurationHandler"/>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System.Configuration.ConfigurationManager, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" >
<section name="Doghunter.My.MySettings" type="System.Configuration.ClientSettingsSection, System.Configuration.ConfigurationManager, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" requirePermission="false" />
</sectionGroup>
</configSections>
<system.diagnostics>
<sources>
<!-- This section defines the logging configuration for My.Application.Log -->
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog"/>
<!-- Uncomment the below section to write to the Application Event Log -->
<!--<add name="EventLog"/>-->
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information" />
</switches>
<sharedListeners>
<add name="FileLog"
type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
initializeData="FileLogWriter"/>
<!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="Doghunter"/>
</sharedListeners>
</system.diagnostics>
<applicationSettings>
<Doghunter.My.MySettings>
<setting name="TestKey" serializeAs="String">
<value>Henry</value>
</setting>
<setting name="NewKey" serializeAs="String">
<value>Moscow</value>
</setting>
</Doghunter.My.MySettings>
</applicationSettings>
</configuration>
Rebuilding the project as a Windows Forms Application (.Net Framework 4.7.2) resolved it.
Originally chose 'plain' Windows Forms Application, which used 5.0
No idea why this is the case, but now works so all good.

VS 2015 IntelliSense: Assembly Not Referenced Error

I just switched to VS 2015. I have an older MVC 5 app that runs against 4.52. In VS 2013 it's perfectly fine.
In VS 2015 I'm getting red squigglies under my #Html.TextBoxFor() with an error indicating:
The type 'Expression<>' is defined in an assembly that is not
referenced. You must add a reference to assembly 'System.Core,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
The project builds and runs just fine -- but I am concerned about the IntelliSense error that never happened in VS 2013. Okay, so I try to add the reference to System.Core as recommended in the error above and then I get this error:
A reference to 'System.Core' could not be added. This component is
already automatically referenced by the build system.
Again, this is fine in VS 2013.
I had the same issue, but in the mean time I've found the answer:
I had to add the following references to my web.config (add inside the opening system.web tag):
<compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<add assembly="System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<add assembly="Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
I also changed the target framework from 4.5.1 to 4.5.
p.s Close and reopen Visual Studio after changing it.
I have tried most of these, what eventually worked for me was unloading the project, edit the csproj file, and add the following:
<Reference Include="System.Core" />
In my case (VS 2019) I have to add this in .csproj file after unload the project
<Reference Include="System.Core" />
need to change in ProjectGuid tag like below:
<ProjectGuid>{6C651A5E-8DDA-4680-804E-F9596743CBE8}</ProjectGuid>
then reload the project and add this tag to web.config like below:
<compilation debug="true" ...>
<assemblies>
<add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
...
</assemblies>
</compilation>
and after that just rebuild the project and all the error is gone in my case.
Only deleting solution and getting solution from source control solved this for me, removing .vs folder and starting VS2015 as "devenv.exe /resetuserdata" did not solve my problem, event removing MEF component cache did not solve as per Razor intellisense not working in VS 2015 answers.
In my case, it worked after changing the tag <ProjectGuid> in .csproj file to <ProjectGuid>{6C651A5E-8DDA-4680-804E-F9596743CBE8}</ProjectGuid> and reopening the solution. All of the solutions posted above did not work for me.
From updating from 4.5.2 to 4.6.1 I got these exact errors in my views. Building and running the solution worked absolutely fine. After trying all the solutions already posted here, (and also checking intellisense for working, clearing caches, removing bin and obj folders, loading and reloading the project) nothing worked whatsoever (system.core was already being built correctly and adding in those references to the Web.config did nothing). I did my own digging and eventually found that in the project where the error was occurring the Web.config file contained two compilation debug target frameworks and a different httpRuntime target framework. Like so:
<system.web>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.6.1" />
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.1" />
...
The solution was to resolve this by removing the extra compilation debug target framework and to ensure all target frameworks were the one I wanted (4.6.1)
<system.web>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.6.1" />
...
Double check this if nothing else works. Hope that helps someone!
If anybody is facing this issue with
VS 2017 , .net framework version 4.8 and MVC version 5.2.7
Then check your Microsoft.CodeDom.Providers.DotNetCompilerPlatform version, If you have 2.0.1 version installed then downgrade it to 2.0.0
Then check the MVC version, you have to downgrade it to 5.2.4
Then downgrade Microsoft.AspNet.WebPages 3.2.7 to Microsoft.AspNet.WebPages 3.2.4
and Microsoft.AspNet.Razor 3.2.7 to Microsoft.AspNet.Razor 3.2.4
try to run the application now, it will work.
I tried these and other solutions on other Stack Overflow threads. None worked.
What worked was repairing the installation of Visual Studio which is found in the System Settings, Apps & features sub-menu (click on VS and choose "Repair"). It took a couple of hours, but then the problem disappeared.

MVC 4 Beta side by side installation error

I just installed the MVC 4 Beta now my MVC 3 application does not compile with the following error:
The type 'System.Web.Mvc.ModelClientValidationRule' exists in both 'c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies\System.Web.Mvc.dll' and 'c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v2.0\Assemblies\System.Web.WebPages.dll' C:\Users\michaeljo\Documents\src\patientgive\Phc.Mvc\Infrastructure\PasswordStrengthAttribute.cs
It would appear this has been moved to a different assembly and since both assemblies are in the GAC it does not know which to use.
After installing MVC4 beta today, a few of my MVC 3 projects would not compile. (ModelClientValidationRule conflict) The fix was:
Edit:
ProjectName.csproj
Change
<Reference Include="System.Web.WebPages"/>
To
<Reference Include="System.Web.WebPages, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL "/>
Ok try this solution...
In the root Web.config file, add a new entry with the key webPages:Version and the value 1.0.0.0.
<appSettings>
<add key="webpages:Version" value="1.0.0.0"/>
<add key="webpages:Version" value="1.0.0.0"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
2.In Solution Explorer, right-click the project name and then select Unload Project. Then right-click the name again and select Edit ProjectName.csproj.
3.Locate the following assembly references:
<Reference Include="System.Web.WebPages"/>
<Reference Include="System.Web.Helpers" />
Replace them with the following:
<Reference Include="System.Web.WebPages, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL "/>
<Reference Include="System.Web.Helpers, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL "/>
4.Save the changes, close the project (.csproj) file you were editing, and then right-click the project and select Reload.
REFERENCE
also try this
I Found this answer here for me the second edit combined with the first solved the problem.
Just remove the reference of System.Web.WebPages. This will build your project successfully.

NHibernate not outputting SQL to console

I have configured NHibernate to output the SQL it generates to the console. I have added the following to the app.config of the DLL containing the integration tests I want to run from NUnit:
<configSections>
<section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<nhibernate>
<add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
<add key="hibernate.show_sql" value="true" />
</nhibernate>
However, the SQL is still not being output to Console.Out. Can anyone think of another setting I might need to set to view the SQL resulting from my NHibernate queries?
Did you try using a sepparate xml config? http://nhibernate.info/doc/howto/various/configure-log4net-for-use-with-nhibernate.html

MSBuild: building website using AspNetCompiler - adding references?

I'm attempting to build a ASP.NET website using MSBuild - specifically the AspNetCompiler tag. I know that, for my project, I need to add some references. Within Visual Studio I have several references, one is a project reference and the others are some DLLS (AjaxControlToolkit etc). I'm happy not referencing the project and referencing the DLL instead - however I just can't work out how to add a reference. I've looked up and down and this is what I've found so far:
<Target Name = "PrecompileWeb">
<AspNetCompiler
VirtualPath = "DeployTemp"
PhysicalPath = "D:\AutoBuild\CruiseControl\Projects\Websites\MyCompany\2.0.0\WorkingDirectory\VSS"
TargetPath = "D:\AutoBuild\CruiseControl\Projects\Websites\MyCompany\2.0.0\PreCompiled"
Force = "true"
Debug = "true"
Updateable = "true"/>
</Target>
Also - I've picked up this bit of code from around the web somewhere, which I thought might help:
<ItemGroup>
<Reference Include="My.Web.DataEngine, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>D:\AutoBuild\CruiseControl\Projects\Components\My.Web.DataEngine\bin\Debug\My.Web.DataEngine.dll</HintPath>
</Reference>
</ItemGroup>
What I want to do is add a attribute to the AspNetCompiler tag, something like:
References="#(Reference)"
but MSBuild isn't very happy about this.
I've been a bit stuck in not being able to find decent references on doing this anywhere: so I'd really apprechiate some pointers or reference material etc. (or just the answer!)
Thanks for you help.
-tom
The aspnet_compiler tool doesn't have a reference property.
Have you looked at using Web Deployment Projects (2005 version)?
You can add references to assemblies used during the compilation of an ASP.NET application by adding to the <assemblies> element, under <compilation> if your web.config. For example:
<compilation targetFramework="4.6.2" debug="true">
<assemblies>
<add assembly="System.Web.Mvc, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
Read more here: https://learn.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/bfyb45k1(v=vs.100)