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.
Related
I'm trying to create a NuGet package that runs an external application before build. That application creates a compilationtime.h file to know the time of compilation to show it in the About dialog box.
My NuGet package has a Tools folder with the CreateCompilationTimeFile.exe and an Build folder with {packagename}.props file.
I've tried a lot of combinations to create the Pre-Build event in the {packagename}.props file but none of them is working.
I tried with this:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemDefinitionGroup>
<PreBuildEvent>
<Command>"$(MSBuildThisFileDirectory)..\tools\CreateCompilationTimeFile.exe"</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
</Project>
Also with this:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="BeforeBuild2" BeforeTargets="Build">
<Exec Command="$(MSBuildThisFileDirectory)..\tools\CreateCompilationTimeFile.exe"/>
</Target>
</Project>
If I do it without the NuGet package and I do it with the next property sheet, it works correctly:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup>
<PreBuildEvent>
<Command>"$(SolutionDir)Tools\CreateCompilationTimeFile.exe"</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup />
</Project>
But I want to do it with the NuGet package and not with property sheets.
What am I doing wrong?
Thanks.
As #leo-liu-msft says, the second solution works, but it's not working as expected, as I will explain below.
If the {packagename}.props contains this:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="CreateCompilationFileTimeTarget" BeforeTargets="Build">
<Exec Command="$(MSBuildThisFileDirectory)..\tools\CreateCompilationTimeFile.exe"/>
</Target>
</Project>
Suppose that you just created a brand new C++ project and include compilationtime.h file in one of your .cpp files:
#include "compilationtime.h"
Remember, the project is new and you don't have any compilationtime.h file jet, it is supposed to be created before the build process because of the {packagename}.props.
If you build your C++ project, you'll get a C0183 Cannot open include file: 'CompilationTime.h': No such file or directory error.
If then you open the project folder, the compilationtime.h file is not where it supposes to be.
Now comment the #include "compilationfile.h" line and compile it again. The compiler will finish without any errors and if you analyze the folder, the file will be there!
Now that your compilationfile.h already exists, edit it and change the tm_year to 0 for example:
#pragma once
static struct tm GetCompilationTime()
{
struct tm compilationTime = { 0 };
compilationTime.tm_year=0;
compilationTime.tm_mon=9;
compilationTime.tm_mday=15;
compilationTime.tm_hour=15;
compilationTime.tm_min=37;
compilationTime.tm_sec=41;
return compilationTime;
}
..and then in your .cpp file, print the year to the console:
#include "pch.h"
#include <iostream>
#include "CompilationTime.h"
int main()
{
std::cout << GetCompilationTime().tm_year << std::endl;
}
Compile and run the program. The program will print 0 and not the current year, but if you open the compilationtime.h file, it is modified with the current year, so the compiler is behaving as if instead of BeforeTargets="Build" we had configured AfterTargets="Build".
Finally I solved the problem changing the BeforeTargets to PrepareForBuild like this:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="CreateCompilationFileTimeTarget" BeforeTargets="PrepareForBuild">
<Exec Command="$(MSBuildThisFileDirectory)..\tools\CreateCompilationTimeFile.exe"/>
</Target>
</Project>
and now it creates/updates the compilationtime.h file always before build as I wanted.
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 ... -->
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>
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
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.