How to force MVC views errors to fail project compilation? - asp.net-mvc-3

Currently, when I compile, I don't see in compilation windows any errors from cshtml views.
Only if I open views I could see problems red-line underlined. That's it.
I need my compilation to fail if there are errors in views.
Thanks.

Open your csproj file in notepad and change the MvcBuildViews property to true.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<!-- other properties ... -->
<MvcBuildViews>true</MvcBuildViews>
<!-- the rest of your project file ... -->

Related

ToolsVersion in Visual Studio 2019

I am doing the migration of several projects from VS2010 to VS2019. Those projects have Tools Version 4 in their vcxprojs:
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
Target VS is VS2019 v16.5.0, MSBuild version is 16.5.0.12403, so I am trying to set ToolsVersion to 16.5:
<Project DefaultTargets="Build" ToolsVersion="16.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
But it seems that MSBuild doesn't like it:
1>Building with tools version "Current".
1>Project file contains ToolsVersion="16.5". This toolset may be unknown or missing, in which case you may be able to resolve this by installing the appropriate version of MSBuild, or the build may have been forced to a particular ToolsVersion for policy reasons. Treating the project as if it had ToolsVersion="Current".
Despite builds are anyway successful, I care about this message. What can be wrong here?
UPD:
Providing simplified example of structure of projects:
common props:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ShouldUnsetParentConfigurationAndPlatform>false</ShouldUnsetParentConfigurationAndPlatform>
</PropertyGroup>
<PropertyGroup Label="Globals">
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<DotNetFrameworkVersion>v4.0</DotNetFrameworkVersion>
</PropertyGroup>
<!-- Other common variables-->
</Project>
cpp props:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
</PropertyGroup>
<PropertyGroup>
<TargetExt>.dll</TargetExt>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="common.props" />
<-- compiler, linker settings and so on -->
</Project>
Real project:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="16.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<ProjectName>my_name</ProjectName>
<ProjectGuid>{my_guid}</ProjectGuid>
<RootNamespace>my_ns</RootNamespace>
<Keyword>my_keyword</Keyword>
</PropertyGroup>
<Import Project="cpp.props" />
<-- configurations (Release, Debug, x64/Win32 and so on -->
<-- project-specific compiler/linker settings -->
<-- items: cpp, heanders and so on -->
<-- references -->
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
Project file contains ToolsVersion="16.5". This toolset may be unknown
or missing
To solve this issue, you should do some updates.
Suggestion
1), right-click on the project on VS2019 IDE-->Retarget Projects and target this project to the Windows 10 SDK version and choose upgrade to v142.
2), Right-click your project on VS2019 IDE-->unload project-->Edit (project name).vcxproj-->change ToolsVersion="4.0" to ToolsVersion="Current"--> then reload your project
3) Right-click on your project-->Properties-->Configuration Properties-->General-->change Platform Toolset to Visual Studio 2019 v142.
----------------Update 1-----------
First of all, ToolVersion is related to the version of MSBuild that is included in the Visual Studio edition like. And in general, we do not use 16.5 in VS2019. See this link. And actually, In VS2019, the ToolVersion is set to Current.
VS2019-->Current, VS2017-->15.0,VS2015-->14.0
You cannot include a specific small version number.
This is my test result with your sample in my side and it seems that it is just like a warning:
It means that it cannot specify the Illegal toolversion 16.5.
Solution
1) Just as I said before, change toolversion to Current in Realproject.vcxproj.
2) delete the toolversion xml node in Realproject.vcxproj and in VS2019, it will automatically recognize toolversion without adding it manually.
To prove it, you can create a new VS2019 c++ project and I am sure that you cannot find toolversion node in xxxx.vcxproj file.
Then try my solution into every projects and I am sure when you finish it, the info will not appear again.

VS2010 - Using <Import /> to share properties between setup projects?

Why doesn't it work to <Import /> this file, when it works when I replace the statement with just copy-pasting the three properties?
../../Setup.Version.proj
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<InstallerMajorVersion>7</InstallerMajorVersion>
<InstallerMinorVersion>7</InstallerMinorVersion>
<InstallerBuildNumber>7</InstallerBuildNumber>
</PropertyGroup>
</Project>
Works:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<InstallerMajorVersion>7</InstallerMajorVersion>
<InstallerMinorVersion>7</InstallerMinorVersion>
<InstallerBuildNumber>7</InstallerBuildNumber>
<OutputName>asdf-$(InstallerMajorVersion).$(InstallerMinorVersion).$(InstallerBuildNumber)</OutputName>
<OutputType>Package</OutputType>
Doesn't work:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="../../Setup.Version.proj" />
<PropertyGroup>
<OutputName>asdf-$(InstallerMajorVersion).$(InstallerMinorVersion).$(InstallerBuildNumber)</OutputName>
<OutputType>Package</OutputType>
Here the variables just evaulate to empty strings... :( I'm certain the path to the imported project is correct.
So it seems to work fine when i run msbuild from the command line, but not when I build the project inside Visual Studio. Why in the world?
I've tried to reproduce and everything works:
importme.proj
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<InstallerMajorVersion>7</InstallerMajorVersion>
<InstallerMinorVersion>7</InstallerMinorVersion>
<InstallerBuildNumber>7</InstallerBuildNumber>
</PropertyGroup>
</Project>
main.proj
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="importme.proj" />
<PropertyGroup>
<OutputName>asdf-$(InstallerMajorVersion).$(InstallerMinorVersion).$(InstallerBuildNumber)</OutputName>
<OutputType>Package</OutputType>
</PropertyGroup>
<Target Name="Build">
<Message Text="$(OutputName)"/>
</Target>
</Project>
OUTPUT
Microsoft (R) Build Engine version 4.0.30319.17626
[Microsoft .NET Framework, version 4.0.30319.17626]
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 10.09.2012 12:35:12.
Project "d:\temp\SO\main.proj" on node 1 (default targets).
Build:
asdf-7.7.7
Done Building Project "d:\temp\SO\main.proj" (default targets).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.55
Run using
msbuild main.proj
UPDATE: You need to reload project for Include'd files to be updated or use workaround.
The reason it didn't work is that Visual Studio had cached the included file, so that any changes I made to it didn't take effect until I reloaded the solution or restarted Visual Studio. This seems to be a limitation of VS 2010. After reloading VS 2010, everything worked as expected.
The Import element is only valid under the Project element. However, the code appears to want to import the values into a <ProjectGroup> element. Try declaring the values as variables in Setup.Version.proj and reference them in your main MSBuild file, such as:
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="../../Setup.Version.proj" /> <!-- Variables declared in here -->
<PropertyGroup>
<InstallerMajorVersion>$(MyInstallerMajorVersion)</InstallerMajorVersion>
<InstallerMinorVersion>$(MyInstallerMinorVersion)</InstallerMinorVersion>
<InstallerBuildNumber>$(MyInstallerBuildNumber)</InstallerBuildNumber>
<OutputName>asdf-$(InstallerMajorVersion).$(InstallerMinorVersion).$(InstallerBuildNumber)</OutputName>
<OutputType>Package</OutputType>

Windows phone 7 localization miss <SupportedCultures> element

I am building a localized wp7 application by following the MSDN article "How to: Build a Localized Application for Windows Phone". here is the link
The article says that I need to add each addintional language in <SupportedCultures> element in my project.csproj file. But I couldn't find any <SupportedCultures> element in the project.csproj file. Can anyone tell where I can put the <SupportedCultures> element. Thanks.
Here is the code in project.csproj file.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="GUID">
<SilverlightMobileCSProjectFlavor>
<FullDeploy>False</FullDeploy>
</SilverlightMobileCSProjectFlavor>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
</Project>
Your project file should have a lot more than just that!
But here is what you requested, all you have to do is merge your XML with this:
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SupportedCultures></SupportedCultures>
</PropertyGroup>
</Project>
You opened the "project.csproj.user" file. Be sure to open exactly "project.csproj" file.

Can I use a property sheet to generate project configurations?

I'm trying to avoid hard coding settings into my .vcxproj files. I'd like to edit a single file, i.e. inherited property sheets (.props), to change my settings. This works great for compiler and linker settings. I also use this technique for all my dependent libraries like boost, zlib, for appending the include path and the libpath.
I'd like to take this a step farther and create the list of configurations in one property sheet.
Is this possible. I keep getting a error.
proj1.vcxproj
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="configurations.props"/>
<PropertyGroup Label="Globals">
<ProjectGuid>{36327322-B9FA-4D71-1111-E94F5BB55D57}</ProjectGuid>
<RootNamespace>Proj1</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
</Project>
configurations.props
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="DebugUnicode|Win32">
<Configuration>DebugUnicode</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
</Project>
proj1.vcxproj : error : Project "proj1" does not contain any
configuration. The project cannot be loaded.
So is this possible?
Sorry, that is a bug I reported in VS 2010 Beta 2, but a fix didn't make RTM.
Link to Connect bug report

How can I create a common post build event used by multiple csproj projects

I have several Visual Studio 2010 C# projects. I'd like to have them all have the same post build event. Basically I want them to copy their output somewhere. I think I can do this using an <import> statement in each csproj file, but I can't seem to figure out the properties/targets and such that I need in the imported file. Do you have any suggestions?
EDIT: I've tried the following but can't get it to work. This is what the Imports.props file looks like:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="AfterBuild">
<Message Text="Here I come to save the day!" />
</Target>
</Project>
I then Include it in the csproj files:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="Imports.props" />
...
I've also tried this as Imports.props:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PostBuildEvent>echo Here I come to save the day!</PostBuildEvent>
</PropertyGroup>
</Project>
Make sure that you import your targets file after the Microsoft.Common.targets import, as that file defines an empty AfterBuild target, which would override the definition in your targets file.
<import> in each projectfile and a <AfterBuild> target in your common build file.
CommonTargets
http://msdn.microsoft.com/en-us/library/ms171464.aspx
TargetOrder
http://msdn.microsoft.com/en-us/library/ms171462.aspx
I managed to share a build script via the property sheets, by writing it as a macro in the inherited property sheet. Then calling the macro in any of the projects that need them.
Macros are found under (VS2005):
Common Properties->User Macros
Remember, you can put macros inside other macros so long as the order is correct.

Resources